blob: dd5bf708218f947dd5ba32fab6fba8e5ff96a231 [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")
230}
231
232func TestBasicZipApex(t *testing.T) {
233 ctx := testApex(t, `
234 apex {
235 name: "myapex",
236 key: "myapex.key",
237 payload_type: "zip",
238 native_shared_libs: ["mylib"],
239 }
240
241 apex_key {
242 name: "myapex.key",
243 public_key: "testkey.avbpubkey",
244 private_key: "testkey.pem",
245 }
246
247 cc_library {
248 name: "mylib",
249 srcs: ["mylib.cpp"],
250 shared_libs: ["mylib2"],
251 system_shared_libs: [],
252 stl: "none",
253 }
254
255 cc_library {
256 name: "mylib2",
257 srcs: ["mylib.cpp"],
258 system_shared_libs: [],
259 stl: "none",
260 }
261 `)
262
263 zipApexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("zipApexRule")
264 copyCmds := zipApexRule.Args["copy_commands"]
265
266 // Ensure that main rule creates an output
267 ensureContains(t, zipApexRule.Output.String(), "myapex.zipapex.unsigned")
268
269 // Ensure that APEX variant is created for the direct dep
Jiyong Parkda6eb592018-12-19 17:12:36 +0900270 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex")
Alex Light5098a612018-11-29 17:12:15 -0800271
272 // Ensure that APEX variant is created for the indirect dep
Jiyong Parkda6eb592018-12-19 17:12:36 +0900273 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared_myapex")
Alex Light5098a612018-11-29 17:12:15 -0800274
275 // Ensure that both direct and indirect deps are copied into apex
276 ensureContains(t, copyCmds, "image.zipapex/lib64/mylib.so")
277 ensureContains(t, copyCmds, "image.zipapex/lib64/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900278}
279
280func TestApexWithStubs(t *testing.T) {
281 ctx := testApex(t, `
282 apex {
283 name: "myapex",
284 key: "myapex.key",
285 native_shared_libs: ["mylib", "mylib3"],
286 }
287
288 apex_key {
289 name: "myapex.key",
290 public_key: "testkey.avbpubkey",
291 private_key: "testkey.pem",
292 }
293
294 cc_library {
295 name: "mylib",
296 srcs: ["mylib.cpp"],
297 shared_libs: ["mylib2", "mylib3"],
298 system_shared_libs: [],
299 stl: "none",
300 }
301
302 cc_library {
303 name: "mylib2",
304 srcs: ["mylib.cpp"],
Jiyong Park64379952018-12-13 18:37:29 +0900305 cflags: ["-include mylib.h"],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900306 system_shared_libs: [],
307 stl: "none",
308 stubs: {
309 versions: ["1", "2", "3"],
310 },
311 }
312
313 cc_library {
314 name: "mylib3",
Jiyong Park28d395a2018-12-07 22:42:47 +0900315 srcs: ["mylib.cpp"],
316 shared_libs: ["mylib4"],
317 system_shared_libs: [],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900318 stl: "none",
319 stubs: {
320 versions: ["10", "11", "12"],
321 },
322 }
Jiyong Park28d395a2018-12-07 22:42:47 +0900323
324 cc_library {
325 name: "mylib4",
326 srcs: ["mylib.cpp"],
327 system_shared_libs: [],
328 stl: "none",
329 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900330 `)
331
332 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
333 copyCmds := apexRule.Args["copy_commands"]
334
335 // Ensure that direct non-stubs dep is always included
Alex Light5098a612018-11-29 17:12:15 -0800336 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900337
338 // Ensure that indirect stubs dep is not included
Alex Light5098a612018-11-29 17:12:15 -0800339 ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900340
341 // Ensure that direct stubs dep is included
Alex Light5098a612018-11-29 17:12:15 -0800342 ensureContains(t, copyCmds, "image.apex/lib64/mylib3.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900343
Jiyong Parkda6eb592018-12-19 17:12:36 +0900344 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_shared_myapex").Rule("ld").Args["libFlags"]
Jiyong Park25fc6a92018-11-18 18:02:45 +0900345
346 // Ensure that mylib is linking with the latest version of stubs for mylib2
Jiyong Parkda6eb592018-12-19 17:12:36 +0900347 ensureContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_core_shared_3_myapex/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900348 // ... and not linking to the non-stub (impl) variant of mylib2
Jiyong Parkda6eb592018-12-19 17:12:36 +0900349 ensureNotContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_core_shared_myapex/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900350
351 // 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 +0900352 ensureContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_core_shared_myapex/mylib3.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900353 // .. and not linking to the stubs variant of mylib3
Jiyong Parkda6eb592018-12-19 17:12:36 +0900354 ensureNotContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_core_shared_12_myapex/mylib3.so")
Jiyong Park64379952018-12-13 18:37:29 +0900355
356 // Ensure that stubs libs are built without -include flags
Jiyong Parkda6eb592018-12-19 17:12:36 +0900357 mylib2Cflags := ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"]
Jiyong Park64379952018-12-13 18:37:29 +0900358 ensureNotContains(t, mylib2Cflags, "-include ")
Jiyong Park3fd0baf2018-12-07 16:25:39 +0900359
360 // Ensure that genstub is invoked with --apex
Jiyong Parkda6eb592018-12-19 17:12:36 +0900361 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 +0900362}
363
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900364func TestApexWithExplicitStubsDependency(t *testing.T) {
365 ctx := testApex(t, `
366 apex {
367 name: "myapex",
368 key: "myapex.key",
369 native_shared_libs: ["mylib"],
370 }
371
372 apex_key {
373 name: "myapex.key",
374 public_key: "testkey.avbpubkey",
375 private_key: "testkey.pem",
376 }
377
378 cc_library {
379 name: "mylib",
380 srcs: ["mylib.cpp"],
381 shared_libs: ["libfoo#10"],
382 system_shared_libs: [],
383 stl: "none",
384 }
385
386 cc_library {
387 name: "libfoo",
388 srcs: ["mylib.cpp"],
389 shared_libs: ["libbar"],
390 system_shared_libs: [],
391 stl: "none",
392 stubs: {
393 versions: ["10", "20", "30"],
394 },
395 }
396
397 cc_library {
398 name: "libbar",
399 srcs: ["mylib.cpp"],
400 system_shared_libs: [],
401 stl: "none",
402 }
403
404 `)
405
406 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
407 copyCmds := apexRule.Args["copy_commands"]
408
409 // Ensure that direct non-stubs dep is always included
410 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
411
412 // Ensure that indirect stubs dep is not included
413 ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so")
414
415 // Ensure that dependency of stubs is not included
416 ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so")
417
Jiyong Parkda6eb592018-12-19 17:12:36 +0900418 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_shared_myapex").Rule("ld").Args["libFlags"]
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900419
420 // Ensure that mylib is linking with version 10 of libfoo
Jiyong Parkda6eb592018-12-19 17:12:36 +0900421 ensureContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_core_shared_10_myapex/libfoo.so")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900422 // ... and not linking to the non-stub (impl) variant of libfoo
Jiyong Parkda6eb592018-12-19 17:12:36 +0900423 ensureNotContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_core_shared_myapex/libfoo.so")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900424
Jiyong Parkda6eb592018-12-19 17:12:36 +0900425 libFooStubsLdFlags := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_core_shared_10_myapex").Rule("ld").Args["libFlags"]
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900426
427 // Ensure that libfoo stubs is not linking to libbar (since it is a stubs)
428 ensureNotContains(t, libFooStubsLdFlags, "libbar.so")
429}
430
Jiyong Park25fc6a92018-11-18 18:02:45 +0900431func TestApexWithSystemLibsStubs(t *testing.T) {
432 ctx := testApex(t, `
433 apex {
434 name: "myapex",
435 key: "myapex.key",
436 native_shared_libs: ["mylib", "mylib_shared", "libdl", "libm"],
437 }
438
439 apex_key {
440 name: "myapex.key",
441 public_key: "testkey.avbpubkey",
442 private_key: "testkey.pem",
443 }
444
445 cc_library {
446 name: "mylib",
447 srcs: ["mylib.cpp"],
448 shared_libs: ["libdl#27"],
449 stl: "none",
450 }
451
452 cc_library_shared {
453 name: "mylib_shared",
454 srcs: ["mylib.cpp"],
455 shared_libs: ["libdl#27"],
456 stl: "none",
457 }
458
459 cc_library {
460 name: "libc",
461 no_libgcc: true,
462 nocrt: true,
463 system_shared_libs: [],
464 stl: "none",
465 stubs: {
466 versions: ["27", "28", "29"],
467 },
468 }
469
470 cc_library {
471 name: "libm",
472 no_libgcc: true,
473 nocrt: true,
474 system_shared_libs: [],
475 stl: "none",
476 stubs: {
477 versions: ["27", "28", "29"],
478 },
479 }
480
481 cc_library {
482 name: "libdl",
483 no_libgcc: true,
484 nocrt: true,
485 system_shared_libs: [],
486 stl: "none",
487 stubs: {
488 versions: ["27", "28", "29"],
489 },
490 }
491 `)
492
493 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
494 copyCmds := apexRule.Args["copy_commands"]
495
496 // Ensure that mylib, libm, libdl are included.
Alex Light5098a612018-11-29 17:12:15 -0800497 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
498 ensureContains(t, copyCmds, "image.apex/lib64/libm.so")
499 ensureContains(t, copyCmds, "image.apex/lib64/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900500
501 // Ensure that libc is not included (since it has stubs and not listed in native_shared_libs)
Alex Light5098a612018-11-29 17:12:15 -0800502 ensureNotContains(t, copyCmds, "image.apex/lib64/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900503
Jiyong Parkda6eb592018-12-19 17:12:36 +0900504 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_shared_myapex").Rule("ld").Args["libFlags"]
505 mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"]
506 mylibSharedCFlags := ctx.ModuleForTests("mylib_shared", "android_arm64_armv8-a_core_shared_myapex").Rule("cc").Args["cFlags"]
Jiyong Park25fc6a92018-11-18 18:02:45 +0900507
508 // For dependency to libc
509 // Ensure that mylib is linking with the latest version of stubs
Jiyong Parkda6eb592018-12-19 17:12:36 +0900510 ensureContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_core_shared_29_myapex/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900511 // ... and not linking to the non-stub (impl) variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900512 ensureNotContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_core_shared_myapex/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900513 // ... Cflags from stub is correctly exported to mylib
514 ensureContains(t, mylibCFlags, "__LIBC_API__=29")
515 ensureContains(t, mylibSharedCFlags, "__LIBC_API__=29")
516
517 // For dependency to libm
518 // Ensure that mylib is linking with the non-stub (impl) variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900519 ensureContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_core_shared_myapex/libm.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900520 // ... and not linking to the stub variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900521 ensureNotContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_core_shared_29_myapex/libm.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900522 // ... and is not compiling with the stub
523 ensureNotContains(t, mylibCFlags, "__LIBM_API__=29")
524 ensureNotContains(t, mylibSharedCFlags, "__LIBM_API__=29")
525
526 // For dependency to libdl
527 // Ensure that mylib is linking with the specified version of stubs
Jiyong Parkda6eb592018-12-19 17:12:36 +0900528 ensureContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_27_myapex/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900529 // ... and not linking to the other versions of stubs
Jiyong Parkda6eb592018-12-19 17:12:36 +0900530 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_28_myapex/libdl.so")
531 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_29_myapex/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900532 // ... and not linking to the non-stub (impl) variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900533 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_myapex/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900534 // ... Cflags from stub is correctly exported to mylib
535 ensureContains(t, mylibCFlags, "__LIBDL_API__=27")
536 ensureContains(t, mylibSharedCFlags, "__LIBDL_API__=27")
537}
Jiyong Park7c2ee712018-12-07 00:42:25 +0900538
539func TestFilesInSubDir(t *testing.T) {
540 ctx := testApex(t, `
541 apex {
542 name: "myapex",
543 key: "myapex.key",
544 prebuilts: ["myetc"],
545 }
546
547 apex_key {
548 name: "myapex.key",
549 public_key: "testkey.avbpubkey",
550 private_key: "testkey.pem",
551 }
552
553 prebuilt_etc {
554 name: "myetc",
555 src: "myprebuilt",
556 sub_dir: "foo/bar",
557 }
558 `)
559
560 generateFsRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("generateFsConfig")
561 dirs := strings.Split(generateFsRule.Args["exec_paths"], " ")
562
563 // Ensure that etc, etc/foo, and etc/foo/bar are all listed
564 ensureListContains(t, dirs, "etc")
565 ensureListContains(t, dirs, "etc/foo")
566 ensureListContains(t, dirs, "etc/foo/bar")
567}
Jiyong Parkda6eb592018-12-19 17:12:36 +0900568
569func TestUseVendor(t *testing.T) {
570 ctx := testApex(t, `
571 apex {
572 name: "myapex",
573 key: "myapex.key",
574 native_shared_libs: ["mylib"],
575 use_vendor: true,
576 }
577
578 apex_key {
579 name: "myapex.key",
580 public_key: "testkey.avbpubkey",
581 private_key: "testkey.pem",
582 }
583
584 cc_library {
585 name: "mylib",
586 srcs: ["mylib.cpp"],
587 shared_libs: ["mylib2"],
588 system_shared_libs: [],
589 vendor_available: true,
590 stl: "none",
591 }
592
593 cc_library {
594 name: "mylib2",
595 srcs: ["mylib.cpp"],
596 system_shared_libs: [],
597 vendor_available: true,
598 stl: "none",
599 }
600 `)
601
602 inputsList := []string{}
603 for _, i := range ctx.ModuleForTests("myapex", "android_common_myapex").Module().BuildParamsForTests() {
604 for _, implicit := range i.Implicits {
605 inputsList = append(inputsList, implicit.String())
606 }
607 }
608 inputsString := strings.Join(inputsList, " ")
609
610 // ensure that the apex includes vendor variants of the direct and indirect deps
611 ensureContains(t, inputsString, "android_arm64_armv8-a_vendor_shared_myapex/mylib.so")
612 ensureContains(t, inputsString, "android_arm64_armv8-a_vendor_shared_myapex/mylib2.so")
613
614 // ensure that the apex does not include core variants
615 ensureNotContains(t, inputsString, "android_arm64_armv8-a_core_shared_myapex/mylib.so")
616 ensureNotContains(t, inputsString, "android_arm64_armv8-a_core_shared_myapex/mylib2.so")
617}
Jiyong Park16e91a02018-12-20 18:18:08 +0900618
619func TestStaticLinking(t *testing.T) {
620 ctx := testApex(t, `
621 apex {
622 name: "myapex",
623 key: "myapex.key",
624 native_shared_libs: ["mylib"],
625 }
626
627 apex_key {
628 name: "myapex.key",
629 public_key: "testkey.avbpubkey",
630 private_key: "testkey.pem",
631 }
632
633 cc_library {
634 name: "mylib",
635 srcs: ["mylib.cpp"],
636 system_shared_libs: [],
637 stl: "none",
638 stubs: {
639 versions: ["1", "2", "3"],
640 },
641 }
642
643 cc_binary {
644 name: "not_in_apex",
645 srcs: ["mylib.cpp"],
646 static_libs: ["mylib"],
647 static_executable: true,
648 system_shared_libs: [],
649 stl: "none",
650 }
651
652 cc_object {
653 name: "crtbegin_static",
654 stl: "none",
655 }
656
657 cc_object {
658 name: "crtend_android",
659 stl: "none",
660 }
661
662 `)
663
664 ldFlags := ctx.ModuleForTests("not_in_apex", "android_arm64_armv8-a_core").Rule("ld").Args["libFlags"]
665
666 // Ensure that not_in_apex is linking with the static variant of mylib
667 ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_core_static/mylib.a")
668}