blob: f8f9b33b45e7ae79d431966e366cec61f41dc3b0 [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 Park25fc6a92018-11-18 18:02:45 +090027)
28
29func testApex(t *testing.T, bp string) *android.TestContext {
30 config, buildDir := setup(t)
31 defer teardown(buildDir)
32
33 ctx := android.NewTestArchContext()
Alex Lightee250722018-12-06 14:00:02 -080034 ctx.RegisterModuleType("apex", android.ModuleFactoryAdaptor(ApexBundleFactory))
Jiyong Park25fc6a92018-11-18 18:02:45 +090035 ctx.RegisterModuleType("apex_key", android.ModuleFactoryAdaptor(apexKeyFactory))
36
37 ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
38 ctx.TopDown("apex_deps", apexDepsMutator)
39 ctx.BottomUp("apex", apexMutator)
40 })
41
42 ctx.RegisterModuleType("cc_library", android.ModuleFactoryAdaptor(cc.LibraryFactory))
43 ctx.RegisterModuleType("cc_library_shared", android.ModuleFactoryAdaptor(cc.LibrarySharedFactory))
Jiyong Park16e91a02018-12-20 18:18:08 +090044 ctx.RegisterModuleType("cc_binary", android.ModuleFactoryAdaptor(cc.BinaryFactory))
Jiyong Park25fc6a92018-11-18 18:02:45 +090045 ctx.RegisterModuleType("cc_object", android.ModuleFactoryAdaptor(cc.ObjectFactory))
Jiyong Parkda6eb592018-12-19 17:12:36 +090046 ctx.RegisterModuleType("llndk_library", android.ModuleFactoryAdaptor(cc.LlndkLibraryFactory))
Jiyong Park25fc6a92018-11-18 18:02:45 +090047 ctx.RegisterModuleType("toolchain_library", android.ModuleFactoryAdaptor(cc.ToolchainLibraryFactory))
Jiyong Park7c2ee712018-12-07 00:42:25 +090048 ctx.RegisterModuleType("prebuilt_etc", android.ModuleFactoryAdaptor(android.PrebuiltEtcFactory))
Jiyong Park25fc6a92018-11-18 18:02:45 +090049 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Jiyong Parkda6eb592018-12-19 17:12:36 +090050 ctx.BottomUp("image", cc.ImageMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +090051 ctx.BottomUp("link", cc.LinkageMutator).Parallel()
Jiyong Parkda6eb592018-12-19 17:12:36 +090052 ctx.BottomUp("vndk", cc.VndkMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +090053 ctx.BottomUp("version", cc.VersionMutator).Parallel()
54 ctx.BottomUp("begin", cc.BeginMutator).Parallel()
55 })
56
57 ctx.Register()
58
59 bp = bp + `
60 toolchain_library {
61 name: "libcompiler_rt-extras",
62 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +090063 vendor_available: true,
64 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +090065 }
66
67 toolchain_library {
68 name: "libatomic",
69 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +090070 vendor_available: true,
71 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +090072 }
73
74 toolchain_library {
75 name: "libgcc",
76 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +090077 vendor_available: true,
78 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +090079 }
80
81 toolchain_library {
82 name: "libclang_rt.builtins-aarch64-android",
83 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +090084 vendor_available: true,
85 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +090086 }
87
88 toolchain_library {
89 name: "libclang_rt.builtins-arm-android",
90 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +090091 vendor_available: true,
92 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +090093 }
94
95 cc_object {
96 name: "crtbegin_so",
97 stl: "none",
Jiyong Parkda6eb592018-12-19 17:12:36 +090098 vendor_available: true,
99 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900100 }
101
102 cc_object {
103 name: "crtend_so",
104 stl: "none",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900105 vendor_available: true,
106 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900107 }
108
Jiyong Parkda6eb592018-12-19 17:12:36 +0900109 llndk_library {
110 name: "libc",
111 symbol_file: "",
112 }
113
114 llndk_library {
115 name: "libm",
116 symbol_file: "",
117 }
118
119 llndk_library {
120 name: "libdl",
121 symbol_file: "",
122 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900123 `
124
125 ctx.MockFileSystem(map[string][]byte{
126 "Android.bp": []byte(bp),
127 "testkey.avbpubkey": nil,
128 "testkey.pem": nil,
129 "build/target/product/security": nil,
130 "apex_manifest.json": nil,
131 "system/sepolicy/apex/myapex-file_contexts": nil,
132 "mylib.cpp": nil,
Jiyong Park7c2ee712018-12-07 00:42:25 +0900133 "myprebuilt": nil,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900134 })
135 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
136 android.FailIfErrored(t, errs)
137 _, errs = ctx.PrepareBuildActions(config)
138 android.FailIfErrored(t, errs)
139
140 return ctx
141}
142
143func setup(t *testing.T) (config android.Config, buildDir string) {
144 buildDir, err := ioutil.TempDir("", "soong_apex_test")
145 if err != nil {
146 t.Fatal(err)
147 }
148
149 config = android.TestArchConfig(buildDir, nil)
Jiyong Parkda6eb592018-12-19 17:12:36 +0900150 config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900151 return
152}
153
154func teardown(buildDir string) {
155 os.RemoveAll(buildDir)
156}
157
158// ensure that 'result' contains 'expected'
159func ensureContains(t *testing.T, result string, expected string) {
160 if !strings.Contains(result, expected) {
161 t.Errorf("%q is not found in %q", expected, result)
162 }
163}
164
165// ensures that 'result' does not contain 'notExpected'
166func ensureNotContains(t *testing.T, result string, notExpected string) {
167 if strings.Contains(result, notExpected) {
168 t.Errorf("%q is found in %q", notExpected, result)
169 }
170}
171
172func ensureListContains(t *testing.T, result []string, expected string) {
173 if !android.InList(expected, result) {
174 t.Errorf("%q is not found in %v", expected, result)
175 }
176}
177
178func ensureListNotContains(t *testing.T, result []string, notExpected string) {
179 if android.InList(notExpected, result) {
180 t.Errorf("%q is found in %v", notExpected, result)
181 }
182}
183
184// Minimal test
185func TestBasicApex(t *testing.T) {
186 ctx := testApex(t, `
187 apex {
188 name: "myapex",
189 key: "myapex.key",
190 native_shared_libs: ["mylib"],
191 }
192
193 apex_key {
194 name: "myapex.key",
195 public_key: "testkey.avbpubkey",
196 private_key: "testkey.pem",
197 }
198
199 cc_library {
200 name: "mylib",
201 srcs: ["mylib.cpp"],
202 shared_libs: ["mylib2"],
203 system_shared_libs: [],
204 stl: "none",
205 }
206
207 cc_library {
208 name: "mylib2",
209 srcs: ["mylib.cpp"],
210 system_shared_libs: [],
211 stl: "none",
212 }
213 `)
214
215 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
216 copyCmds := apexRule.Args["copy_commands"]
217
218 // Ensure that main rule creates an output
219 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
220
221 // Ensure that apex variant is created for the direct dep
Jiyong Parkda6eb592018-12-19 17:12:36 +0900222 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900223
224 // Ensure that apex variant is created for the indirect dep
Jiyong Parkda6eb592018-12-19 17:12:36 +0900225 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared_myapex")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900226
227 // Ensure that both direct and indirect deps are copied into apex
Alex Light5098a612018-11-29 17:12:15 -0800228 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
229 ensureContains(t, copyCmds, "image.apex/lib64/mylib2.so")
Logan Chien3aeedc92018-12-26 15:32:21 +0800230
231 // Ensure that the platform variant ends with _core_shared
232 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared")
233 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared")
Alex Light5098a612018-11-29 17:12:15 -0800234}
235
236func TestBasicZipApex(t *testing.T) {
237 ctx := testApex(t, `
238 apex {
239 name: "myapex",
240 key: "myapex.key",
241 payload_type: "zip",
242 native_shared_libs: ["mylib"],
243 }
244
245 apex_key {
246 name: "myapex.key",
247 public_key: "testkey.avbpubkey",
248 private_key: "testkey.pem",
249 }
250
251 cc_library {
252 name: "mylib",
253 srcs: ["mylib.cpp"],
254 shared_libs: ["mylib2"],
255 system_shared_libs: [],
256 stl: "none",
257 }
258
259 cc_library {
260 name: "mylib2",
261 srcs: ["mylib.cpp"],
262 system_shared_libs: [],
263 stl: "none",
264 }
265 `)
266
267 zipApexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("zipApexRule")
268 copyCmds := zipApexRule.Args["copy_commands"]
269
270 // Ensure that main rule creates an output
271 ensureContains(t, zipApexRule.Output.String(), "myapex.zipapex.unsigned")
272
273 // Ensure that APEX variant is created for the direct dep
Jiyong Parkda6eb592018-12-19 17:12:36 +0900274 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex")
Alex Light5098a612018-11-29 17:12:15 -0800275
276 // Ensure that APEX variant is created for the indirect dep
Jiyong Parkda6eb592018-12-19 17:12:36 +0900277 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared_myapex")
Alex Light5098a612018-11-29 17:12:15 -0800278
279 // Ensure that both direct and indirect deps are copied into apex
280 ensureContains(t, copyCmds, "image.zipapex/lib64/mylib.so")
281 ensureContains(t, copyCmds, "image.zipapex/lib64/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900282}
283
284func TestApexWithStubs(t *testing.T) {
285 ctx := testApex(t, `
286 apex {
287 name: "myapex",
288 key: "myapex.key",
289 native_shared_libs: ["mylib", "mylib3"],
290 }
291
292 apex_key {
293 name: "myapex.key",
294 public_key: "testkey.avbpubkey",
295 private_key: "testkey.pem",
296 }
297
298 cc_library {
299 name: "mylib",
300 srcs: ["mylib.cpp"],
301 shared_libs: ["mylib2", "mylib3"],
302 system_shared_libs: [],
303 stl: "none",
304 }
305
306 cc_library {
307 name: "mylib2",
308 srcs: ["mylib.cpp"],
Jiyong Park64379952018-12-13 18:37:29 +0900309 cflags: ["-include mylib.h"],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900310 system_shared_libs: [],
311 stl: "none",
312 stubs: {
313 versions: ["1", "2", "3"],
314 },
315 }
316
317 cc_library {
318 name: "mylib3",
Jiyong Park28d395a2018-12-07 22:42:47 +0900319 srcs: ["mylib.cpp"],
320 shared_libs: ["mylib4"],
321 system_shared_libs: [],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900322 stl: "none",
323 stubs: {
324 versions: ["10", "11", "12"],
325 },
326 }
Jiyong Park28d395a2018-12-07 22:42:47 +0900327
328 cc_library {
329 name: "mylib4",
330 srcs: ["mylib.cpp"],
331 system_shared_libs: [],
332 stl: "none",
333 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900334 `)
335
336 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
337 copyCmds := apexRule.Args["copy_commands"]
338
339 // Ensure that direct non-stubs dep is always included
Alex Light5098a612018-11-29 17:12:15 -0800340 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900341
342 // Ensure that indirect stubs dep is not included
Alex Light5098a612018-11-29 17:12:15 -0800343 ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900344
345 // Ensure that direct stubs dep is included
Alex Light5098a612018-11-29 17:12:15 -0800346 ensureContains(t, copyCmds, "image.apex/lib64/mylib3.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900347
Jiyong Parkda6eb592018-12-19 17:12:36 +0900348 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_shared_myapex").Rule("ld").Args["libFlags"]
Jiyong Park25fc6a92018-11-18 18:02:45 +0900349
350 // Ensure that mylib is linking with the latest version of stubs for mylib2
Jiyong Parkda6eb592018-12-19 17:12:36 +0900351 ensureContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_core_shared_3_myapex/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900352 // ... and not linking to the non-stub (impl) variant of mylib2
Jiyong Parkda6eb592018-12-19 17:12:36 +0900353 ensureNotContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_core_shared_myapex/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900354
355 // 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 +0900356 ensureContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_core_shared_myapex/mylib3.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900357 // .. and not linking to the stubs variant of mylib3
Jiyong Parkda6eb592018-12-19 17:12:36 +0900358 ensureNotContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_core_shared_12_myapex/mylib3.so")
Jiyong Park64379952018-12-13 18:37:29 +0900359
360 // Ensure that stubs libs are built without -include flags
Jiyong Parkda6eb592018-12-19 17:12:36 +0900361 mylib2Cflags := ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"]
Jiyong Park64379952018-12-13 18:37:29 +0900362 ensureNotContains(t, mylib2Cflags, "-include ")
Jiyong Park3fd0baf2018-12-07 16:25:39 +0900363
364 // Ensure that genstub is invoked with --apex
Jiyong Parkda6eb592018-12-19 17:12:36 +0900365 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 +0900366}
367
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900368func TestApexWithExplicitStubsDependency(t *testing.T) {
369 ctx := testApex(t, `
370 apex {
371 name: "myapex",
372 key: "myapex.key",
373 native_shared_libs: ["mylib"],
374 }
375
376 apex_key {
377 name: "myapex.key",
378 public_key: "testkey.avbpubkey",
379 private_key: "testkey.pem",
380 }
381
382 cc_library {
383 name: "mylib",
384 srcs: ["mylib.cpp"],
385 shared_libs: ["libfoo#10"],
386 system_shared_libs: [],
387 stl: "none",
388 }
389
390 cc_library {
391 name: "libfoo",
392 srcs: ["mylib.cpp"],
393 shared_libs: ["libbar"],
394 system_shared_libs: [],
395 stl: "none",
396 stubs: {
397 versions: ["10", "20", "30"],
398 },
399 }
400
401 cc_library {
402 name: "libbar",
403 srcs: ["mylib.cpp"],
404 system_shared_libs: [],
405 stl: "none",
406 }
407
408 `)
409
410 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
411 copyCmds := apexRule.Args["copy_commands"]
412
413 // Ensure that direct non-stubs dep is always included
414 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
415
416 // Ensure that indirect stubs dep is not included
417 ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so")
418
419 // Ensure that dependency of stubs is not included
420 ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so")
421
Jiyong Parkda6eb592018-12-19 17:12:36 +0900422 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_shared_myapex").Rule("ld").Args["libFlags"]
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900423
424 // Ensure that mylib is linking with version 10 of libfoo
Jiyong Parkda6eb592018-12-19 17:12:36 +0900425 ensureContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_core_shared_10_myapex/libfoo.so")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900426 // ... and not linking to the non-stub (impl) variant of libfoo
Jiyong Parkda6eb592018-12-19 17:12:36 +0900427 ensureNotContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_core_shared_myapex/libfoo.so")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900428
Jiyong Parkda6eb592018-12-19 17:12:36 +0900429 libFooStubsLdFlags := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_core_shared_10_myapex").Rule("ld").Args["libFlags"]
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900430
431 // Ensure that libfoo stubs is not linking to libbar (since it is a stubs)
432 ensureNotContains(t, libFooStubsLdFlags, "libbar.so")
433}
434
Jiyong Park25fc6a92018-11-18 18:02:45 +0900435func TestApexWithSystemLibsStubs(t *testing.T) {
436 ctx := testApex(t, `
437 apex {
438 name: "myapex",
439 key: "myapex.key",
440 native_shared_libs: ["mylib", "mylib_shared", "libdl", "libm"],
441 }
442
443 apex_key {
444 name: "myapex.key",
445 public_key: "testkey.avbpubkey",
446 private_key: "testkey.pem",
447 }
448
449 cc_library {
450 name: "mylib",
451 srcs: ["mylib.cpp"],
452 shared_libs: ["libdl#27"],
453 stl: "none",
454 }
455
456 cc_library_shared {
457 name: "mylib_shared",
458 srcs: ["mylib.cpp"],
459 shared_libs: ["libdl#27"],
460 stl: "none",
461 }
462
463 cc_library {
464 name: "libc",
465 no_libgcc: true,
466 nocrt: true,
467 system_shared_libs: [],
468 stl: "none",
469 stubs: {
470 versions: ["27", "28", "29"],
471 },
472 }
473
474 cc_library {
475 name: "libm",
476 no_libgcc: true,
477 nocrt: true,
478 system_shared_libs: [],
479 stl: "none",
480 stubs: {
481 versions: ["27", "28", "29"],
482 },
483 }
484
485 cc_library {
486 name: "libdl",
487 no_libgcc: true,
488 nocrt: true,
489 system_shared_libs: [],
490 stl: "none",
491 stubs: {
492 versions: ["27", "28", "29"],
493 },
494 }
495 `)
496
497 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
498 copyCmds := apexRule.Args["copy_commands"]
499
500 // Ensure that mylib, libm, libdl are included.
Alex Light5098a612018-11-29 17:12:15 -0800501 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
502 ensureContains(t, copyCmds, "image.apex/lib64/libm.so")
503 ensureContains(t, copyCmds, "image.apex/lib64/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900504
505 // Ensure that libc is not included (since it has stubs and not listed in native_shared_libs)
Alex Light5098a612018-11-29 17:12:15 -0800506 ensureNotContains(t, copyCmds, "image.apex/lib64/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900507
Jiyong Parkda6eb592018-12-19 17:12:36 +0900508 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_shared_myapex").Rule("ld").Args["libFlags"]
509 mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"]
510 mylibSharedCFlags := ctx.ModuleForTests("mylib_shared", "android_arm64_armv8-a_core_shared_myapex").Rule("cc").Args["cFlags"]
Jiyong Park25fc6a92018-11-18 18:02:45 +0900511
512 // For dependency to libc
513 // Ensure that mylib is linking with the latest version of stubs
Jiyong Parkda6eb592018-12-19 17:12:36 +0900514 ensureContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_core_shared_29_myapex/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900515 // ... and not linking to the non-stub (impl) variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900516 ensureNotContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_core_shared_myapex/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900517 // ... Cflags from stub is correctly exported to mylib
518 ensureContains(t, mylibCFlags, "__LIBC_API__=29")
519 ensureContains(t, mylibSharedCFlags, "__LIBC_API__=29")
520
521 // For dependency to libm
522 // Ensure that mylib is linking with the non-stub (impl) variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900523 ensureContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_core_shared_myapex/libm.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900524 // ... and not linking to the stub variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900525 ensureNotContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_core_shared_29_myapex/libm.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900526 // ... and is not compiling with the stub
527 ensureNotContains(t, mylibCFlags, "__LIBM_API__=29")
528 ensureNotContains(t, mylibSharedCFlags, "__LIBM_API__=29")
529
530 // For dependency to libdl
531 // Ensure that mylib is linking with the specified version of stubs
Jiyong Parkda6eb592018-12-19 17:12:36 +0900532 ensureContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_27_myapex/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900533 // ... and not linking to the other versions of stubs
Jiyong Parkda6eb592018-12-19 17:12:36 +0900534 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_28_myapex/libdl.so")
535 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_29_myapex/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900536 // ... and not linking to the non-stub (impl) variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900537 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_myapex/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900538 // ... Cflags from stub is correctly exported to mylib
539 ensureContains(t, mylibCFlags, "__LIBDL_API__=27")
540 ensureContains(t, mylibSharedCFlags, "__LIBDL_API__=27")
541}
Jiyong Park7c2ee712018-12-07 00:42:25 +0900542
543func TestFilesInSubDir(t *testing.T) {
544 ctx := testApex(t, `
545 apex {
546 name: "myapex",
547 key: "myapex.key",
548 prebuilts: ["myetc"],
549 }
550
551 apex_key {
552 name: "myapex.key",
553 public_key: "testkey.avbpubkey",
554 private_key: "testkey.pem",
555 }
556
557 prebuilt_etc {
558 name: "myetc",
559 src: "myprebuilt",
560 sub_dir: "foo/bar",
561 }
562 `)
563
564 generateFsRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("generateFsConfig")
565 dirs := strings.Split(generateFsRule.Args["exec_paths"], " ")
566
567 // Ensure that etc, etc/foo, and etc/foo/bar are all listed
568 ensureListContains(t, dirs, "etc")
569 ensureListContains(t, dirs, "etc/foo")
570 ensureListContains(t, dirs, "etc/foo/bar")
571}
Jiyong Parkda6eb592018-12-19 17:12:36 +0900572
573func TestUseVendor(t *testing.T) {
574 ctx := testApex(t, `
575 apex {
576 name: "myapex",
577 key: "myapex.key",
578 native_shared_libs: ["mylib"],
579 use_vendor: true,
580 }
581
582 apex_key {
583 name: "myapex.key",
584 public_key: "testkey.avbpubkey",
585 private_key: "testkey.pem",
586 }
587
588 cc_library {
589 name: "mylib",
590 srcs: ["mylib.cpp"],
591 shared_libs: ["mylib2"],
592 system_shared_libs: [],
593 vendor_available: true,
594 stl: "none",
595 }
596
597 cc_library {
598 name: "mylib2",
599 srcs: ["mylib.cpp"],
600 system_shared_libs: [],
601 vendor_available: true,
602 stl: "none",
603 }
604 `)
605
606 inputsList := []string{}
607 for _, i := range ctx.ModuleForTests("myapex", "android_common_myapex").Module().BuildParamsForTests() {
608 for _, implicit := range i.Implicits {
609 inputsList = append(inputsList, implicit.String())
610 }
611 }
612 inputsString := strings.Join(inputsList, " ")
613
614 // ensure that the apex includes vendor variants of the direct and indirect deps
615 ensureContains(t, inputsString, "android_arm64_armv8-a_vendor_shared_myapex/mylib.so")
616 ensureContains(t, inputsString, "android_arm64_armv8-a_vendor_shared_myapex/mylib2.so")
617
618 // ensure that the apex does not include core variants
619 ensureNotContains(t, inputsString, "android_arm64_armv8-a_core_shared_myapex/mylib.so")
620 ensureNotContains(t, inputsString, "android_arm64_armv8-a_core_shared_myapex/mylib2.so")
621}
Jiyong Park16e91a02018-12-20 18:18:08 +0900622
623func TestStaticLinking(t *testing.T) {
624 ctx := testApex(t, `
625 apex {
626 name: "myapex",
627 key: "myapex.key",
628 native_shared_libs: ["mylib"],
629 }
630
631 apex_key {
632 name: "myapex.key",
633 public_key: "testkey.avbpubkey",
634 private_key: "testkey.pem",
635 }
636
637 cc_library {
638 name: "mylib",
639 srcs: ["mylib.cpp"],
640 system_shared_libs: [],
641 stl: "none",
642 stubs: {
643 versions: ["1", "2", "3"],
644 },
645 }
646
647 cc_binary {
648 name: "not_in_apex",
649 srcs: ["mylib.cpp"],
650 static_libs: ["mylib"],
651 static_executable: true,
652 system_shared_libs: [],
653 stl: "none",
654 }
655
656 cc_object {
657 name: "crtbegin_static",
658 stl: "none",
659 }
660
661 cc_object {
662 name: "crtend_android",
663 stl: "none",
664 }
665
666 `)
667
668 ldFlags := ctx.ModuleForTests("not_in_apex", "android_arm64_armv8-a_core").Rule("ld").Args["libFlags"]
669
670 // Ensure that not_in_apex is linking with the static variant of mylib
Logan Chien3aeedc92018-12-26 15:32:21 +0800671 ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_core_static/mylib.a")
Jiyong Park16e91a02018-12-20 18:18:08 +0900672}