blob: ac2701f7eded11eccbbb784625fe41f6ab246f46 [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"
20 "strings"
21 "testing"
Jiyong Parkda6eb592018-12-19 17:12:36 +090022
23 "github.com/google/blueprint/proptools"
24
25 "android/soong/android"
26 "android/soong/cc"
Jiyong Parkb2742fd2019-02-11 11:38:15 +090027 "android/soong/java"
Jiyong Park25fc6a92018-11-18 18:02:45 +090028)
29
30func testApex(t *testing.T, bp string) *android.TestContext {
31 config, buildDir := setup(t)
32 defer teardown(buildDir)
33
34 ctx := android.NewTestArchContext()
Alex Light0851b882019-02-07 13:20:53 -080035 ctx.RegisterModuleType("apex", android.ModuleFactoryAdaptor(apexBundleFactory))
36 ctx.RegisterModuleType("apex_test", android.ModuleFactoryAdaptor(testApexBundleFactory))
Jiyong Park25fc6a92018-11-18 18:02:45 +090037 ctx.RegisterModuleType("apex_key", android.ModuleFactoryAdaptor(apexKeyFactory))
Jiyong Park30ca9372019-02-07 16:27:23 +090038 ctx.RegisterModuleType("apex_defaults", android.ModuleFactoryAdaptor(defaultsFactory))
39 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Jiyong Park25fc6a92018-11-18 18:02:45 +090040
41 ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
42 ctx.TopDown("apex_deps", apexDepsMutator)
43 ctx.BottomUp("apex", apexMutator)
44 })
45
46 ctx.RegisterModuleType("cc_library", android.ModuleFactoryAdaptor(cc.LibraryFactory))
47 ctx.RegisterModuleType("cc_library_shared", android.ModuleFactoryAdaptor(cc.LibrarySharedFactory))
Jiyong Park7e636d02019-01-28 16:16:54 +090048 ctx.RegisterModuleType("cc_library_headers", android.ModuleFactoryAdaptor(cc.LibraryHeaderFactory))
Jiyong Park16e91a02018-12-20 18:18:08 +090049 ctx.RegisterModuleType("cc_binary", android.ModuleFactoryAdaptor(cc.BinaryFactory))
Jiyong Park25fc6a92018-11-18 18:02:45 +090050 ctx.RegisterModuleType("cc_object", android.ModuleFactoryAdaptor(cc.ObjectFactory))
Jiyong Parkda6eb592018-12-19 17:12:36 +090051 ctx.RegisterModuleType("llndk_library", android.ModuleFactoryAdaptor(cc.LlndkLibraryFactory))
Jiyong Park25fc6a92018-11-18 18:02:45 +090052 ctx.RegisterModuleType("toolchain_library", android.ModuleFactoryAdaptor(cc.ToolchainLibraryFactory))
Jiyong Park7c2ee712018-12-07 00:42:25 +090053 ctx.RegisterModuleType("prebuilt_etc", android.ModuleFactoryAdaptor(android.PrebuiltEtcFactory))
Jiyong Park04480cf2019-02-06 00:16:29 +090054 ctx.RegisterModuleType("sh_binary", android.ModuleFactoryAdaptor(android.ShBinaryFactory))
Jiyong Parkb2742fd2019-02-11 11:38:15 +090055 ctx.RegisterModuleType("android_app_certificate", android.ModuleFactoryAdaptor(java.AndroidAppCertificateFactory))
Jiyong Park809bb722019-02-13 21:33:49 +090056 ctx.RegisterModuleType("filegroup", android.ModuleFactoryAdaptor(android.FileGroupFactory))
Jiyong Park25fc6a92018-11-18 18:02:45 +090057 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Jiyong Parkda6eb592018-12-19 17:12:36 +090058 ctx.BottomUp("image", cc.ImageMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +090059 ctx.BottomUp("link", cc.LinkageMutator).Parallel()
Jiyong Parkda6eb592018-12-19 17:12:36 +090060 ctx.BottomUp("vndk", cc.VndkMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +090061 ctx.BottomUp("version", cc.VersionMutator).Parallel()
62 ctx.BottomUp("begin", cc.BeginMutator).Parallel()
63 })
64
65 ctx.Register()
66
67 bp = bp + `
68 toolchain_library {
69 name: "libcompiler_rt-extras",
70 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +090071 vendor_available: true,
72 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +090073 }
74
75 toolchain_library {
76 name: "libatomic",
77 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +090078 vendor_available: true,
79 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +090080 }
81
82 toolchain_library {
83 name: "libgcc",
84 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +090085 vendor_available: true,
86 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +090087 }
88
89 toolchain_library {
90 name: "libclang_rt.builtins-aarch64-android",
91 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +090092 vendor_available: true,
93 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +090094 }
95
96 toolchain_library {
97 name: "libclang_rt.builtins-arm-android",
98 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +090099 vendor_available: true,
100 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900101 }
102
103 cc_object {
104 name: "crtbegin_so",
105 stl: "none",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900106 vendor_available: true,
107 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900108 }
109
110 cc_object {
111 name: "crtend_so",
112 stl: "none",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900113 vendor_available: true,
114 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900115 }
116
Alex Light3d673592019-01-18 14:37:31 -0800117 cc_object {
118 name: "crtbegin_static",
119 stl: "none",
120 }
121
122 cc_object {
123 name: "crtend_android",
124 stl: "none",
125 }
126
Jiyong Parkda6eb592018-12-19 17:12:36 +0900127 llndk_library {
128 name: "libc",
129 symbol_file: "",
130 }
131
132 llndk_library {
133 name: "libm",
134 symbol_file: "",
135 }
136
137 llndk_library {
138 name: "libdl",
139 symbol_file: "",
140 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900141 `
142
143 ctx.MockFileSystem(map[string][]byte{
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900144 "Android.bp": []byte(bp),
145 "build/target/product/security": nil,
146 "apex_manifest.json": nil,
Jiyong Park809bb722019-02-13 21:33:49 +0900147 "AndroidManifest.xml": nil,
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900148 "system/sepolicy/apex/myapex-file_contexts": nil,
149 "system/sepolicy/apex/myapex_keytest-file_contexts": nil,
150 "system/sepolicy/apex/otherapex-file_contexts": nil,
151 "mylib.cpp": nil,
152 "myprebuilt": nil,
153 "my_include": nil,
154 "vendor/foo/devkeys/test.x509.pem": nil,
155 "vendor/foo/devkeys/test.pk8": nil,
156 "testkey.x509.pem": nil,
157 "testkey.pk8": nil,
158 "testkey.override.x509.pem": nil,
159 "testkey.override.pk8": nil,
160 "vendor/foo/devkeys/testkey.avbpubkey": nil,
161 "vendor/foo/devkeys/testkey.pem": nil,
Jiyong Park52818fc2019-03-18 12:01:38 +0900162 "NOTICE": nil,
163 "custom_notice": nil,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900164 })
165 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
166 android.FailIfErrored(t, errs)
167 _, errs = ctx.PrepareBuildActions(config)
168 android.FailIfErrored(t, errs)
169
170 return ctx
171}
172
173func setup(t *testing.T) (config android.Config, buildDir string) {
174 buildDir, err := ioutil.TempDir("", "soong_apex_test")
175 if err != nil {
176 t.Fatal(err)
177 }
178
179 config = android.TestArchConfig(buildDir, nil)
Jiyong Parkda6eb592018-12-19 17:12:36 +0900180 config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current")
Jiyong Park9335a262018-12-24 11:31:58 +0900181 config.TestProductVariables.DefaultAppCertificate = proptools.StringPtr("vendor/foo/devkeys/test")
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900182 config.TestProductVariables.CertificateOverrides = []string{"myapex_keytest:myapex.certificate.override"}
Jiyong Park25fc6a92018-11-18 18:02:45 +0900183 return
184}
185
186func teardown(buildDir string) {
187 os.RemoveAll(buildDir)
188}
189
190// ensure that 'result' contains 'expected'
191func ensureContains(t *testing.T, result string, expected string) {
192 if !strings.Contains(result, expected) {
193 t.Errorf("%q is not found in %q", expected, result)
194 }
195}
196
197// ensures that 'result' does not contain 'notExpected'
198func ensureNotContains(t *testing.T, result string, notExpected string) {
199 if strings.Contains(result, notExpected) {
200 t.Errorf("%q is found in %q", notExpected, result)
201 }
202}
203
204func ensureListContains(t *testing.T, result []string, expected string) {
205 if !android.InList(expected, result) {
206 t.Errorf("%q is not found in %v", expected, result)
207 }
208}
209
210func ensureListNotContains(t *testing.T, result []string, notExpected string) {
211 if android.InList(notExpected, result) {
212 t.Errorf("%q is found in %v", notExpected, result)
213 }
214}
215
216// Minimal test
217func TestBasicApex(t *testing.T) {
218 ctx := testApex(t, `
Jiyong Park30ca9372019-02-07 16:27:23 +0900219 apex_defaults {
220 name: "myapex-defaults",
Jiyong Park809bb722019-02-13 21:33:49 +0900221 manifest: ":myapex.manifest",
222 androidManifest: ":myapex.androidmanifest",
Jiyong Park25fc6a92018-11-18 18:02:45 +0900223 key: "myapex.key",
224 native_shared_libs: ["mylib"],
Alex Light3d673592019-01-18 14:37:31 -0800225 multilib: {
226 both: {
227 binaries: ["foo",],
228 }
229 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900230 }
231
Jiyong Park30ca9372019-02-07 16:27:23 +0900232 apex {
233 name: "myapex",
234 defaults: ["myapex-defaults"],
235 }
236
Jiyong Park25fc6a92018-11-18 18:02:45 +0900237 apex_key {
238 name: "myapex.key",
239 public_key: "testkey.avbpubkey",
240 private_key: "testkey.pem",
241 }
242
Jiyong Park809bb722019-02-13 21:33:49 +0900243 filegroup {
244 name: "myapex.manifest",
245 srcs: ["apex_manifest.json"],
246 }
247
248 filegroup {
249 name: "myapex.androidmanifest",
250 srcs: ["AndroidManifest.xml"],
251 }
252
Jiyong Park25fc6a92018-11-18 18:02:45 +0900253 cc_library {
254 name: "mylib",
255 srcs: ["mylib.cpp"],
256 shared_libs: ["mylib2"],
257 system_shared_libs: [],
258 stl: "none",
259 }
260
Alex Light3d673592019-01-18 14:37:31 -0800261 cc_binary {
262 name: "foo",
263 srcs: ["mylib.cpp"],
264 compile_multilib: "both",
265 multilib: {
266 lib32: {
267 suffix: "32",
268 },
269 lib64: {
270 suffix: "64",
271 },
272 },
273 symlinks: ["foo_link_"],
274 symlink_preferred_arch: true,
275 system_shared_libs: [],
276 static_executable: true,
277 stl: "none",
278 }
279
Jiyong Park25fc6a92018-11-18 18:02:45 +0900280 cc_library {
281 name: "mylib2",
282 srcs: ["mylib.cpp"],
283 system_shared_libs: [],
284 stl: "none",
Jiyong Park52818fc2019-03-18 12:01:38 +0900285 notice: "custom_notice",
Jiyong Park25fc6a92018-11-18 18:02:45 +0900286 }
287 `)
288
289 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
290 copyCmds := apexRule.Args["copy_commands"]
291
292 // Ensure that main rule creates an output
293 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
294
295 // Ensure that apex variant is created for the direct dep
Jiyong Parkda6eb592018-12-19 17:12:36 +0900296 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900297
298 // Ensure that apex variant is created for the indirect dep
Jiyong Parkda6eb592018-12-19 17:12:36 +0900299 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared_myapex")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900300
301 // Ensure that both direct and indirect deps are copied into apex
Alex Light5098a612018-11-29 17:12:15 -0800302 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
303 ensureContains(t, copyCmds, "image.apex/lib64/mylib2.so")
Logan Chien3aeedc92018-12-26 15:32:21 +0800304
305 // Ensure that the platform variant ends with _core_shared
306 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared")
307 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared")
Alex Light3d673592019-01-18 14:37:31 -0800308
309 // Ensure that all symlinks are present.
310 found_foo_link_64 := false
311 found_foo := false
312 for _, cmd := range strings.Split(copyCmds, " && ") {
313 if strings.HasPrefix(cmd, "ln -s foo64") {
314 if strings.HasSuffix(cmd, "bin/foo") {
315 found_foo = true
316 } else if strings.HasSuffix(cmd, "bin/foo_link_64") {
317 found_foo_link_64 = true
318 }
319 }
320 }
321 good := found_foo && found_foo_link_64
322 if !good {
323 t.Errorf("Could not find all expected symlinks! foo: %t, foo_link_64: %t. Command was %s", found_foo, found_foo_link_64, copyCmds)
324 }
Jiyong Park52818fc2019-03-18 12:01:38 +0900325
326 apexMergeNoticeRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexMergeNoticeRule")
327 noticeInputs := strings.Split(apexMergeNoticeRule.Args["inputs"], " ")
328 if len(noticeInputs) != 3 {
329 t.Errorf("number of input notice files: expected = 3, actual = %d", len(noticeInputs))
330 }
331 ensureListContains(t, noticeInputs, "NOTICE")
332 ensureListContains(t, noticeInputs, "custom_notice")
Alex Light5098a612018-11-29 17:12:15 -0800333}
334
335func TestBasicZipApex(t *testing.T) {
336 ctx := testApex(t, `
337 apex {
338 name: "myapex",
339 key: "myapex.key",
340 payload_type: "zip",
341 native_shared_libs: ["mylib"],
342 }
343
344 apex_key {
345 name: "myapex.key",
346 public_key: "testkey.avbpubkey",
347 private_key: "testkey.pem",
348 }
349
350 cc_library {
351 name: "mylib",
352 srcs: ["mylib.cpp"],
353 shared_libs: ["mylib2"],
354 system_shared_libs: [],
355 stl: "none",
356 }
357
358 cc_library {
359 name: "mylib2",
360 srcs: ["mylib.cpp"],
361 system_shared_libs: [],
362 stl: "none",
363 }
364 `)
365
366 zipApexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("zipApexRule")
367 copyCmds := zipApexRule.Args["copy_commands"]
368
369 // Ensure that main rule creates an output
370 ensureContains(t, zipApexRule.Output.String(), "myapex.zipapex.unsigned")
371
372 // Ensure that APEX variant is created for the direct dep
Jiyong Parkda6eb592018-12-19 17:12:36 +0900373 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex")
Alex Light5098a612018-11-29 17:12:15 -0800374
375 // Ensure that APEX variant is created for the indirect dep
Jiyong Parkda6eb592018-12-19 17:12:36 +0900376 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared_myapex")
Alex Light5098a612018-11-29 17:12:15 -0800377
378 // Ensure that both direct and indirect deps are copied into apex
379 ensureContains(t, copyCmds, "image.zipapex/lib64/mylib.so")
380 ensureContains(t, copyCmds, "image.zipapex/lib64/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900381}
382
383func TestApexWithStubs(t *testing.T) {
384 ctx := testApex(t, `
385 apex {
386 name: "myapex",
387 key: "myapex.key",
388 native_shared_libs: ["mylib", "mylib3"],
389 }
390
391 apex_key {
392 name: "myapex.key",
393 public_key: "testkey.avbpubkey",
394 private_key: "testkey.pem",
395 }
396
397 cc_library {
398 name: "mylib",
399 srcs: ["mylib.cpp"],
400 shared_libs: ["mylib2", "mylib3"],
401 system_shared_libs: [],
402 stl: "none",
403 }
404
405 cc_library {
406 name: "mylib2",
407 srcs: ["mylib.cpp"],
Jiyong Park64379952018-12-13 18:37:29 +0900408 cflags: ["-include mylib.h"],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900409 system_shared_libs: [],
410 stl: "none",
411 stubs: {
412 versions: ["1", "2", "3"],
413 },
414 }
415
416 cc_library {
417 name: "mylib3",
Jiyong Park28d395a2018-12-07 22:42:47 +0900418 srcs: ["mylib.cpp"],
419 shared_libs: ["mylib4"],
420 system_shared_libs: [],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900421 stl: "none",
422 stubs: {
423 versions: ["10", "11", "12"],
424 },
425 }
Jiyong Park28d395a2018-12-07 22:42:47 +0900426
427 cc_library {
428 name: "mylib4",
429 srcs: ["mylib.cpp"],
430 system_shared_libs: [],
431 stl: "none",
432 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900433 `)
434
435 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
436 copyCmds := apexRule.Args["copy_commands"]
437
438 // Ensure that direct non-stubs dep is always included
Alex Light5098a612018-11-29 17:12:15 -0800439 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900440
441 // Ensure that indirect stubs dep is not included
Alex Light5098a612018-11-29 17:12:15 -0800442 ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900443
444 // Ensure that direct stubs dep is included
Alex Light5098a612018-11-29 17:12:15 -0800445 ensureContains(t, copyCmds, "image.apex/lib64/mylib3.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900446
Jiyong Parkda6eb592018-12-19 17:12:36 +0900447 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_shared_myapex").Rule("ld").Args["libFlags"]
Jiyong Park25fc6a92018-11-18 18:02:45 +0900448
449 // Ensure that mylib is linking with the latest version of stubs for mylib2
Jiyong Parkda6eb592018-12-19 17:12:36 +0900450 ensureContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_core_shared_3_myapex/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900451 // ... and not linking to the non-stub (impl) variant of mylib2
Jiyong Parkda6eb592018-12-19 17:12:36 +0900452 ensureNotContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_core_shared_myapex/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900453
454 // Ensure that mylib is linking with the non-stub (impl) of mylib3 (because mylib3 is in the same apex)
Jiyong Parkda6eb592018-12-19 17:12:36 +0900455 ensureContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_core_shared_myapex/mylib3.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900456 // .. and not linking to the stubs variant of mylib3
Jiyong Parkda6eb592018-12-19 17:12:36 +0900457 ensureNotContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_core_shared_12_myapex/mylib3.so")
Jiyong Park64379952018-12-13 18:37:29 +0900458
459 // Ensure that stubs libs are built without -include flags
Jiyong Parkda6eb592018-12-19 17:12:36 +0900460 mylib2Cflags := ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"]
Jiyong Park64379952018-12-13 18:37:29 +0900461 ensureNotContains(t, mylib2Cflags, "-include ")
Jiyong Park3fd0baf2018-12-07 16:25:39 +0900462
463 // Ensure that genstub is invoked with --apex
Jiyong Parkda6eb592018-12-19 17:12:36 +0900464 ensureContains(t, "--apex", ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_core_static_3_myapex").Rule("genStubSrc").Args["flags"])
Jiyong Park25fc6a92018-11-18 18:02:45 +0900465}
466
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900467func TestApexWithExplicitStubsDependency(t *testing.T) {
468 ctx := testApex(t, `
469 apex {
470 name: "myapex",
471 key: "myapex.key",
472 native_shared_libs: ["mylib"],
473 }
474
475 apex_key {
476 name: "myapex.key",
477 public_key: "testkey.avbpubkey",
478 private_key: "testkey.pem",
479 }
480
481 cc_library {
482 name: "mylib",
483 srcs: ["mylib.cpp"],
484 shared_libs: ["libfoo#10"],
485 system_shared_libs: [],
486 stl: "none",
487 }
488
489 cc_library {
490 name: "libfoo",
491 srcs: ["mylib.cpp"],
492 shared_libs: ["libbar"],
493 system_shared_libs: [],
494 stl: "none",
495 stubs: {
496 versions: ["10", "20", "30"],
497 },
498 }
499
500 cc_library {
501 name: "libbar",
502 srcs: ["mylib.cpp"],
503 system_shared_libs: [],
504 stl: "none",
505 }
506
507 `)
508
509 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
510 copyCmds := apexRule.Args["copy_commands"]
511
512 // Ensure that direct non-stubs dep is always included
513 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
514
515 // Ensure that indirect stubs dep is not included
516 ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so")
517
518 // Ensure that dependency of stubs is not included
519 ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so")
520
Jiyong Parkda6eb592018-12-19 17:12:36 +0900521 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_shared_myapex").Rule("ld").Args["libFlags"]
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900522
523 // Ensure that mylib is linking with version 10 of libfoo
Jiyong Parkda6eb592018-12-19 17:12:36 +0900524 ensureContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_core_shared_10_myapex/libfoo.so")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900525 // ... and not linking to the non-stub (impl) variant of libfoo
Jiyong Parkda6eb592018-12-19 17:12:36 +0900526 ensureNotContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_core_shared_myapex/libfoo.so")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900527
Jiyong Parkda6eb592018-12-19 17:12:36 +0900528 libFooStubsLdFlags := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_core_shared_10_myapex").Rule("ld").Args["libFlags"]
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900529
530 // Ensure that libfoo stubs is not linking to libbar (since it is a stubs)
531 ensureNotContains(t, libFooStubsLdFlags, "libbar.so")
532}
533
Jiyong Park25fc6a92018-11-18 18:02:45 +0900534func TestApexWithSystemLibsStubs(t *testing.T) {
535 ctx := testApex(t, `
536 apex {
537 name: "myapex",
538 key: "myapex.key",
539 native_shared_libs: ["mylib", "mylib_shared", "libdl", "libm"],
540 }
541
542 apex_key {
543 name: "myapex.key",
544 public_key: "testkey.avbpubkey",
545 private_key: "testkey.pem",
546 }
547
548 cc_library {
549 name: "mylib",
550 srcs: ["mylib.cpp"],
551 shared_libs: ["libdl#27"],
552 stl: "none",
553 }
554
555 cc_library_shared {
556 name: "mylib_shared",
557 srcs: ["mylib.cpp"],
558 shared_libs: ["libdl#27"],
559 stl: "none",
560 }
561
562 cc_library {
563 name: "libc",
564 no_libgcc: true,
565 nocrt: true,
566 system_shared_libs: [],
567 stl: "none",
568 stubs: {
569 versions: ["27", "28", "29"],
570 },
571 }
572
573 cc_library {
574 name: "libm",
575 no_libgcc: true,
576 nocrt: true,
577 system_shared_libs: [],
578 stl: "none",
579 stubs: {
580 versions: ["27", "28", "29"],
581 },
582 }
583
584 cc_library {
585 name: "libdl",
586 no_libgcc: true,
587 nocrt: true,
588 system_shared_libs: [],
589 stl: "none",
590 stubs: {
591 versions: ["27", "28", "29"],
592 },
593 }
Jiyong Parkb0788572018-12-20 22:10:17 +0900594
595 cc_library {
596 name: "libBootstrap",
597 srcs: ["mylib.cpp"],
598 stl: "none",
599 bootstrap: true,
600 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900601 `)
602
603 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
604 copyCmds := apexRule.Args["copy_commands"]
605
606 // Ensure that mylib, libm, libdl are included.
Alex Light5098a612018-11-29 17:12:15 -0800607 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
Jiyong Parkb0788572018-12-20 22:10:17 +0900608 ensureContains(t, copyCmds, "image.apex/lib64/bionic/libm.so")
609 ensureContains(t, copyCmds, "image.apex/lib64/bionic/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900610
611 // Ensure that libc is not included (since it has stubs and not listed in native_shared_libs)
Jiyong Parkb0788572018-12-20 22:10:17 +0900612 ensureNotContains(t, copyCmds, "image.apex/lib64/bionic/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900613
Jiyong Parkda6eb592018-12-19 17:12:36 +0900614 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_shared_myapex").Rule("ld").Args["libFlags"]
615 mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"]
616 mylibSharedCFlags := ctx.ModuleForTests("mylib_shared", "android_arm64_armv8-a_core_shared_myapex").Rule("cc").Args["cFlags"]
Jiyong Park25fc6a92018-11-18 18:02:45 +0900617
618 // For dependency to libc
619 // Ensure that mylib is linking with the latest version of stubs
Jiyong Parkda6eb592018-12-19 17:12:36 +0900620 ensureContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_core_shared_29_myapex/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900621 // ... and not linking to the non-stub (impl) variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900622 ensureNotContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_core_shared_myapex/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900623 // ... Cflags from stub is correctly exported to mylib
624 ensureContains(t, mylibCFlags, "__LIBC_API__=29")
625 ensureContains(t, mylibSharedCFlags, "__LIBC_API__=29")
626
627 // For dependency to libm
628 // Ensure that mylib is linking with the non-stub (impl) variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900629 ensureContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_core_shared_myapex/libm.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900630 // ... and not linking to the stub variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900631 ensureNotContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_core_shared_29_myapex/libm.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900632 // ... and is not compiling with the stub
633 ensureNotContains(t, mylibCFlags, "__LIBM_API__=29")
634 ensureNotContains(t, mylibSharedCFlags, "__LIBM_API__=29")
635
636 // For dependency to libdl
637 // Ensure that mylib is linking with the specified version of stubs
Jiyong Parkda6eb592018-12-19 17:12:36 +0900638 ensureContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_27_myapex/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900639 // ... and not linking to the other versions of stubs
Jiyong Parkda6eb592018-12-19 17:12:36 +0900640 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_28_myapex/libdl.so")
641 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_29_myapex/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900642 // ... and not linking to the non-stub (impl) variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900643 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_myapex/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900644 // ... Cflags from stub is correctly exported to mylib
645 ensureContains(t, mylibCFlags, "__LIBDL_API__=27")
646 ensureContains(t, mylibSharedCFlags, "__LIBDL_API__=27")
Jiyong Parkb0788572018-12-20 22:10:17 +0900647
648 // Ensure that libBootstrap is depending on the platform variant of bionic libs
649 libFlags := ctx.ModuleForTests("libBootstrap", "android_arm64_armv8-a_core_shared").Rule("ld").Args["libFlags"]
650 ensureContains(t, libFlags, "libc/android_arm64_armv8-a_core_shared/libc.so")
651 ensureContains(t, libFlags, "libm/android_arm64_armv8-a_core_shared/libm.so")
652 ensureContains(t, libFlags, "libdl/android_arm64_armv8-a_core_shared/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900653}
Jiyong Park7c2ee712018-12-07 00:42:25 +0900654
655func TestFilesInSubDir(t *testing.T) {
656 ctx := testApex(t, `
657 apex {
658 name: "myapex",
659 key: "myapex.key",
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900660 native_shared_libs: ["mylib"],
661 binaries: ["mybin"],
Jiyong Park7c2ee712018-12-07 00:42:25 +0900662 prebuilts: ["myetc"],
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900663 compile_multilib: "both",
Jiyong Park7c2ee712018-12-07 00:42:25 +0900664 }
665
666 apex_key {
667 name: "myapex.key",
668 public_key: "testkey.avbpubkey",
669 private_key: "testkey.pem",
670 }
671
672 prebuilt_etc {
673 name: "myetc",
674 src: "myprebuilt",
675 sub_dir: "foo/bar",
676 }
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900677
678 cc_library {
679 name: "mylib",
680 srcs: ["mylib.cpp"],
681 relative_install_path: "foo/bar",
682 system_shared_libs: [],
683 stl: "none",
684 }
685
686 cc_binary {
687 name: "mybin",
688 srcs: ["mylib.cpp"],
689 relative_install_path: "foo/bar",
690 system_shared_libs: [],
691 static_executable: true,
692 stl: "none",
693 }
Jiyong Park7c2ee712018-12-07 00:42:25 +0900694 `)
695
696 generateFsRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("generateFsConfig")
697 dirs := strings.Split(generateFsRule.Args["exec_paths"], " ")
698
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900699 // Ensure that the subdirectories are all listed
Jiyong Park7c2ee712018-12-07 00:42:25 +0900700 ensureListContains(t, dirs, "etc")
701 ensureListContains(t, dirs, "etc/foo")
702 ensureListContains(t, dirs, "etc/foo/bar")
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900703 ensureListContains(t, dirs, "lib64")
704 ensureListContains(t, dirs, "lib64/foo")
705 ensureListContains(t, dirs, "lib64/foo/bar")
706 ensureListContains(t, dirs, "lib")
707 ensureListContains(t, dirs, "lib/foo")
708 ensureListContains(t, dirs, "lib/foo/bar")
709
Jiyong Parkbd13e442019-03-15 18:10:35 +0900710 ensureListContains(t, dirs, "bin")
711 ensureListContains(t, dirs, "bin/foo")
712 ensureListContains(t, dirs, "bin/foo/bar")
Jiyong Park7c2ee712018-12-07 00:42:25 +0900713}
Jiyong Parkda6eb592018-12-19 17:12:36 +0900714
715func TestUseVendor(t *testing.T) {
716 ctx := testApex(t, `
717 apex {
718 name: "myapex",
719 key: "myapex.key",
720 native_shared_libs: ["mylib"],
721 use_vendor: true,
722 }
723
724 apex_key {
725 name: "myapex.key",
726 public_key: "testkey.avbpubkey",
727 private_key: "testkey.pem",
728 }
729
730 cc_library {
731 name: "mylib",
732 srcs: ["mylib.cpp"],
733 shared_libs: ["mylib2"],
734 system_shared_libs: [],
735 vendor_available: true,
736 stl: "none",
737 }
738
739 cc_library {
740 name: "mylib2",
741 srcs: ["mylib.cpp"],
742 system_shared_libs: [],
743 vendor_available: true,
744 stl: "none",
745 }
746 `)
747
748 inputsList := []string{}
749 for _, i := range ctx.ModuleForTests("myapex", "android_common_myapex").Module().BuildParamsForTests() {
750 for _, implicit := range i.Implicits {
751 inputsList = append(inputsList, implicit.String())
752 }
753 }
754 inputsString := strings.Join(inputsList, " ")
755
756 // ensure that the apex includes vendor variants of the direct and indirect deps
757 ensureContains(t, inputsString, "android_arm64_armv8-a_vendor_shared_myapex/mylib.so")
758 ensureContains(t, inputsString, "android_arm64_armv8-a_vendor_shared_myapex/mylib2.so")
759
760 // ensure that the apex does not include core variants
761 ensureNotContains(t, inputsString, "android_arm64_armv8-a_core_shared_myapex/mylib.so")
762 ensureNotContains(t, inputsString, "android_arm64_armv8-a_core_shared_myapex/mylib2.so")
763}
Jiyong Park16e91a02018-12-20 18:18:08 +0900764
765func TestStaticLinking(t *testing.T) {
766 ctx := testApex(t, `
767 apex {
768 name: "myapex",
769 key: "myapex.key",
770 native_shared_libs: ["mylib"],
771 }
772
773 apex_key {
774 name: "myapex.key",
775 public_key: "testkey.avbpubkey",
776 private_key: "testkey.pem",
777 }
778
779 cc_library {
780 name: "mylib",
781 srcs: ["mylib.cpp"],
782 system_shared_libs: [],
783 stl: "none",
784 stubs: {
785 versions: ["1", "2", "3"],
786 },
787 }
788
789 cc_binary {
790 name: "not_in_apex",
791 srcs: ["mylib.cpp"],
792 static_libs: ["mylib"],
793 static_executable: true,
794 system_shared_libs: [],
795 stl: "none",
796 }
Jiyong Park16e91a02018-12-20 18:18:08 +0900797 `)
798
799 ldFlags := ctx.ModuleForTests("not_in_apex", "android_arm64_armv8-a_core").Rule("ld").Args["libFlags"]
800
801 // Ensure that not_in_apex is linking with the static variant of mylib
Logan Chien3aeedc92018-12-26 15:32:21 +0800802 ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_core_static/mylib.a")
Jiyong Park16e91a02018-12-20 18:18:08 +0900803}
Jiyong Park9335a262018-12-24 11:31:58 +0900804
805func TestKeys(t *testing.T) {
806 ctx := testApex(t, `
807 apex {
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900808 name: "myapex_keytest",
Jiyong Park9335a262018-12-24 11:31:58 +0900809 key: "myapex.key",
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900810 certificate: ":myapex.certificate",
Jiyong Park9335a262018-12-24 11:31:58 +0900811 native_shared_libs: ["mylib"],
812 }
813
814 cc_library {
815 name: "mylib",
816 srcs: ["mylib.cpp"],
817 system_shared_libs: [],
818 stl: "none",
819 }
820
821 apex_key {
822 name: "myapex.key",
823 public_key: "testkey.avbpubkey",
824 private_key: "testkey.pem",
825 }
826
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900827 android_app_certificate {
828 name: "myapex.certificate",
829 certificate: "testkey",
830 }
831
832 android_app_certificate {
833 name: "myapex.certificate.override",
834 certificate: "testkey.override",
835 }
836
Jiyong Park9335a262018-12-24 11:31:58 +0900837 `)
838
839 // check the APEX keys
Jiyong Parkd1e293d2019-03-15 02:13:21 +0900840 keys := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey)
Jiyong Park9335a262018-12-24 11:31:58 +0900841
842 if keys.public_key_file.String() != "vendor/foo/devkeys/testkey.avbpubkey" {
843 t.Errorf("public key %q is not %q", keys.public_key_file.String(),
844 "vendor/foo/devkeys/testkey.avbpubkey")
845 }
846 if keys.private_key_file.String() != "vendor/foo/devkeys/testkey.pem" {
847 t.Errorf("private key %q is not %q", keys.private_key_file.String(),
848 "vendor/foo/devkeys/testkey.pem")
849 }
850
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900851 // check the APK certs. It should be overridden to myapex.certificate.override
852 certs := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest").Rule("signapk").Args["certificates"]
853 if certs != "testkey.override.x509.pem testkey.override.pk8" {
Jiyong Park9335a262018-12-24 11:31:58 +0900854 t.Errorf("cert and private key %q are not %q", certs,
Jiyong Parkb2742fd2019-02-11 11:38:15 +0900855 "testkey.override.509.pem testkey.override.pk8")
Jiyong Park9335a262018-12-24 11:31:58 +0900856 }
857}
Jiyong Park58e364a2019-01-19 19:24:06 +0900858
859func TestMacro(t *testing.T) {
860 ctx := testApex(t, `
861 apex {
862 name: "myapex",
863 key: "myapex.key",
864 native_shared_libs: ["mylib"],
865 }
866
867 apex {
868 name: "otherapex",
869 key: "myapex.key",
870 native_shared_libs: ["mylib"],
871 }
872
873 apex_key {
874 name: "myapex.key",
875 public_key: "testkey.avbpubkey",
876 private_key: "testkey.pem",
877 }
878
879 cc_library {
880 name: "mylib",
881 srcs: ["mylib.cpp"],
882 system_shared_libs: [],
883 stl: "none",
884 }
885 `)
886
887 // non-APEX variant does not have __ANDROID__APEX__ defined
888 mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static").Rule("cc").Args["cFlags"]
889 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=myapex")
890 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=otherapex")
891
892 // APEX variant has __ANDROID_APEX__=<apexname> defined
893 mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"]
894 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__=myapex")
895 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=otherapex")
896
897 // APEX variant has __ANDROID_APEX__=<apexname> defined
898 mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_otherapex").Rule("cc").Args["cFlags"]
899 ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=myapex")
900 ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__=otherapex")
901}
Jiyong Park7e636d02019-01-28 16:16:54 +0900902
903func TestHeaderLibsDependency(t *testing.T) {
904 ctx := testApex(t, `
905 apex {
906 name: "myapex",
907 key: "myapex.key",
908 native_shared_libs: ["mylib"],
909 }
910
911 apex_key {
912 name: "myapex.key",
913 public_key: "testkey.avbpubkey",
914 private_key: "testkey.pem",
915 }
916
917 cc_library_headers {
918 name: "mylib_headers",
919 export_include_dirs: ["my_include"],
920 system_shared_libs: [],
921 stl: "none",
922 }
923
924 cc_library {
925 name: "mylib",
926 srcs: ["mylib.cpp"],
927 system_shared_libs: [],
928 stl: "none",
929 header_libs: ["mylib_headers"],
930 export_header_lib_headers: ["mylib_headers"],
931 stubs: {
932 versions: ["1", "2", "3"],
933 },
934 }
935
936 cc_library {
937 name: "otherlib",
938 srcs: ["mylib.cpp"],
939 system_shared_libs: [],
940 stl: "none",
941 shared_libs: ["mylib"],
942 }
943 `)
944
945 cFlags := ctx.ModuleForTests("otherlib", "android_arm64_armv8-a_core_static").Rule("cc").Args["cFlags"]
946
947 // Ensure that the include path of the header lib is exported to 'otherlib'
948 ensureContains(t, cFlags, "-Imy_include")
949}
Alex Light9670d332019-01-29 18:07:33 -0800950
Alex Light0851b882019-02-07 13:20:53 -0800951func TestNonTestApex(t *testing.T) {
952 ctx := testApex(t, `
953 apex {
954 name: "myapex",
955 key: "myapex.key",
956 native_shared_libs: ["mylib_common"],
957 }
958
959 apex_key {
960 name: "myapex.key",
961 public_key: "testkey.avbpubkey",
962 private_key: "testkey.pem",
963 }
964
965 cc_library {
966 name: "mylib_common",
967 srcs: ["mylib.cpp"],
968 system_shared_libs: [],
969 stl: "none",
970 }
971 `)
972
973 module := ctx.ModuleForTests("myapex", "android_common_myapex")
974 apexRule := module.Rule("apexRule")
975 copyCmds := apexRule.Args["copy_commands"]
976
977 if apex, ok := module.Module().(*apexBundle); !ok || apex.testApex {
978 t.Log("Apex was a test apex!")
979 t.Fail()
980 }
981 // Ensure that main rule creates an output
982 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
983
984 // Ensure that apex variant is created for the direct dep
985 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared_myapex")
986
987 // Ensure that both direct and indirect deps are copied into apex
988 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so")
989
990 // Ensure that the platform variant ends with _core_shared
991 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared")
992
993 if !android.InAnyApex("mylib_common") {
994 t.Log("Found mylib_common not in any apex!")
995 t.Fail()
996 }
997}
998
999func TestTestApex(t *testing.T) {
1000 if android.InAnyApex("mylib_common_test") {
1001 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!")
1002 }
1003 ctx := testApex(t, `
1004 apex_test {
1005 name: "myapex",
1006 key: "myapex.key",
1007 native_shared_libs: ["mylib_common_test"],
1008 }
1009
1010 apex_key {
1011 name: "myapex.key",
1012 public_key: "testkey.avbpubkey",
1013 private_key: "testkey.pem",
1014 }
1015
1016 cc_library {
1017 name: "mylib_common_test",
1018 srcs: ["mylib.cpp"],
1019 system_shared_libs: [],
1020 stl: "none",
1021 }
1022 `)
1023
1024 module := ctx.ModuleForTests("myapex", "android_common_myapex")
1025 apexRule := module.Rule("apexRule")
1026 copyCmds := apexRule.Args["copy_commands"]
1027
1028 if apex, ok := module.Module().(*apexBundle); !ok || !apex.testApex {
1029 t.Log("Apex was not a test apex!")
1030 t.Fail()
1031 }
1032 // Ensure that main rule creates an output
1033 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
1034
1035 // Ensure that apex variant is created for the direct dep
1036 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_core_shared_myapex")
1037
1038 // Ensure that both direct and indirect deps are copied into apex
1039 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common_test.so")
1040
1041 // Ensure that the platform variant ends with _core_shared
1042 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_core_shared")
1043
1044 if android.InAnyApex("mylib_common_test") {
1045 t.Log("Found mylib_common_test in some apex!")
1046 t.Fail()
1047 }
1048}
1049
Alex Light9670d332019-01-29 18:07:33 -08001050func TestApexWithTarget(t *testing.T) {
1051 ctx := testApex(t, `
1052 apex {
1053 name: "myapex",
1054 key: "myapex.key",
1055 multilib: {
1056 first: {
1057 native_shared_libs: ["mylib_common"],
1058 }
1059 },
1060 target: {
1061 android: {
1062 multilib: {
1063 first: {
1064 native_shared_libs: ["mylib"],
1065 }
1066 }
1067 },
1068 host: {
1069 multilib: {
1070 first: {
1071 native_shared_libs: ["mylib2"],
1072 }
1073 }
1074 }
1075 }
1076 }
1077
1078 apex_key {
1079 name: "myapex.key",
1080 public_key: "testkey.avbpubkey",
1081 private_key: "testkey.pem",
1082 }
1083
1084 cc_library {
1085 name: "mylib",
1086 srcs: ["mylib.cpp"],
1087 system_shared_libs: [],
1088 stl: "none",
1089 }
1090
1091 cc_library {
1092 name: "mylib_common",
1093 srcs: ["mylib.cpp"],
1094 system_shared_libs: [],
1095 stl: "none",
1096 compile_multilib: "first",
1097 }
1098
1099 cc_library {
1100 name: "mylib2",
1101 srcs: ["mylib.cpp"],
1102 system_shared_libs: [],
1103 stl: "none",
1104 compile_multilib: "first",
1105 }
1106 `)
1107
1108 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
1109 copyCmds := apexRule.Args["copy_commands"]
1110
1111 // Ensure that main rule creates an output
1112 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
1113
1114 // Ensure that apex variant is created for the direct dep
1115 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex")
1116 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared_myapex")
1117 ensureListNotContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared_myapex")
1118
1119 // Ensure that both direct and indirect deps are copied into apex
1120 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
1121 ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so")
1122 ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so")
1123
1124 // Ensure that the platform variant ends with _core_shared
1125 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared")
1126 ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared")
1127 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared")
1128}
Jiyong Park04480cf2019-02-06 00:16:29 +09001129
1130func TestApexWithShBinary(t *testing.T) {
1131 ctx := testApex(t, `
1132 apex {
1133 name: "myapex",
1134 key: "myapex.key",
1135 binaries: ["myscript"],
1136 }
1137
1138 apex_key {
1139 name: "myapex.key",
1140 public_key: "testkey.avbpubkey",
1141 private_key: "testkey.pem",
1142 }
1143
1144 sh_binary {
1145 name: "myscript",
1146 src: "mylib.cpp",
1147 filename: "myscript.sh",
1148 sub_dir: "script",
1149 }
1150 `)
1151
1152 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
1153 copyCmds := apexRule.Args["copy_commands"]
1154
1155 ensureContains(t, copyCmds, "image.apex/bin/script/myscript.sh")
1156}
Jiyong Parkd1e293d2019-03-15 02:13:21 +09001157
1158func TestApexInProductPartition(t *testing.T) {
1159 ctx := testApex(t, `
1160 apex {
1161 name: "myapex",
1162 key: "myapex.key",
1163 native_shared_libs: ["mylib"],
1164 product_specific: true,
1165 }
1166
1167 apex_key {
1168 name: "myapex.key",
1169 public_key: "testkey.avbpubkey",
1170 private_key: "testkey.pem",
1171 product_specific: true,
1172 }
1173
1174 cc_library {
1175 name: "mylib",
1176 srcs: ["mylib.cpp"],
1177 system_shared_libs: [],
1178 stl: "none",
1179 }
1180 `)
1181
1182 apex := ctx.ModuleForTests("myapex", "android_common_myapex").Module().(*apexBundle)
1183 expected := "target/product/test_device/product/apex"
1184 actual := apex.installDir.RelPathString()
1185 if actual != expected {
1186 t.Errorf("wrong install path. expected %q. actual %q", expected, actual)
1187 }
1188
1189 apex_key := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey)
1190 expected = "target/product/test_device/product/etc/security/apex"
1191 actual = apex_key.installDir.RelPathString()
1192 if actual != expected {
1193 t.Errorf("wrong install path. expected %q. actual %q", expected, actual)
1194 }
1195
1196}