blob: 77117c550608c8a1adf7a25dd37d0a2ba7dd31b0 [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))
44 ctx.RegisterModuleType("cc_object", android.ModuleFactoryAdaptor(cc.ObjectFactory))
Jiyong Parkda6eb592018-12-19 17:12:36 +090045 ctx.RegisterModuleType("llndk_library", android.ModuleFactoryAdaptor(cc.LlndkLibraryFactory))
Jiyong Park25fc6a92018-11-18 18:02:45 +090046 ctx.RegisterModuleType("toolchain_library", android.ModuleFactoryAdaptor(cc.ToolchainLibraryFactory))
Jiyong Park7c2ee712018-12-07 00:42:25 +090047 ctx.RegisterModuleType("prebuilt_etc", android.ModuleFactoryAdaptor(android.PrebuiltEtcFactory))
Jiyong Park25fc6a92018-11-18 18:02:45 +090048 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Jiyong Parkda6eb592018-12-19 17:12:36 +090049 ctx.BottomUp("image", cc.ImageMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +090050 ctx.BottomUp("link", cc.LinkageMutator).Parallel()
Jiyong Parkda6eb592018-12-19 17:12:36 +090051 ctx.BottomUp("vndk", cc.VndkMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +090052 ctx.BottomUp("version", cc.VersionMutator).Parallel()
53 ctx.BottomUp("begin", cc.BeginMutator).Parallel()
54 })
55
56 ctx.Register()
57
58 bp = bp + `
59 toolchain_library {
60 name: "libcompiler_rt-extras",
61 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +090062 vendor_available: true,
63 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +090064 }
65
66 toolchain_library {
67 name: "libatomic",
68 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +090069 vendor_available: true,
70 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +090071 }
72
73 toolchain_library {
74 name: "libgcc",
75 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +090076 vendor_available: true,
77 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +090078 }
79
80 toolchain_library {
81 name: "libclang_rt.builtins-aarch64-android",
82 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +090083 vendor_available: true,
84 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +090085 }
86
87 toolchain_library {
88 name: "libclang_rt.builtins-arm-android",
89 src: "",
Jiyong Parkda6eb592018-12-19 17:12:36 +090090 vendor_available: true,
91 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +090092 }
93
94 cc_object {
95 name: "crtbegin_so",
96 stl: "none",
Jiyong Parkda6eb592018-12-19 17:12:36 +090097 vendor_available: true,
98 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +090099 }
100
101 cc_object {
102 name: "crtend_so",
103 stl: "none",
Jiyong Parkda6eb592018-12-19 17:12:36 +0900104 vendor_available: true,
105 recovery_available: true,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900106 }
107
Jiyong Parkda6eb592018-12-19 17:12:36 +0900108 llndk_library {
109 name: "libc",
110 symbol_file: "",
111 }
112
113 llndk_library {
114 name: "libm",
115 symbol_file: "",
116 }
117
118 llndk_library {
119 name: "libdl",
120 symbol_file: "",
121 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900122 `
123
124 ctx.MockFileSystem(map[string][]byte{
125 "Android.bp": []byte(bp),
126 "testkey.avbpubkey": nil,
127 "testkey.pem": nil,
128 "build/target/product/security": nil,
129 "apex_manifest.json": nil,
130 "system/sepolicy/apex/myapex-file_contexts": nil,
131 "mylib.cpp": nil,
Jiyong Park7c2ee712018-12-07 00:42:25 +0900132 "myprebuilt": nil,
Jiyong Park25fc6a92018-11-18 18:02:45 +0900133 })
134 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
135 android.FailIfErrored(t, errs)
136 _, errs = ctx.PrepareBuildActions(config)
137 android.FailIfErrored(t, errs)
138
139 return ctx
140}
141
142func setup(t *testing.T) (config android.Config, buildDir string) {
143 buildDir, err := ioutil.TempDir("", "soong_apex_test")
144 if err != nil {
145 t.Fatal(err)
146 }
147
148 config = android.TestArchConfig(buildDir, nil)
Jiyong Parkda6eb592018-12-19 17:12:36 +0900149 config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900150 return
151}
152
153func teardown(buildDir string) {
154 os.RemoveAll(buildDir)
155}
156
157// ensure that 'result' contains 'expected'
158func ensureContains(t *testing.T, result string, expected string) {
159 if !strings.Contains(result, expected) {
160 t.Errorf("%q is not found in %q", expected, result)
161 }
162}
163
164// ensures that 'result' does not contain 'notExpected'
165func ensureNotContains(t *testing.T, result string, notExpected string) {
166 if strings.Contains(result, notExpected) {
167 t.Errorf("%q is found in %q", notExpected, result)
168 }
169}
170
171func ensureListContains(t *testing.T, result []string, expected string) {
172 if !android.InList(expected, result) {
173 t.Errorf("%q is not found in %v", expected, result)
174 }
175}
176
177func ensureListNotContains(t *testing.T, result []string, notExpected string) {
178 if android.InList(notExpected, result) {
179 t.Errorf("%q is found in %v", notExpected, result)
180 }
181}
182
183// Minimal test
184func TestBasicApex(t *testing.T) {
185 ctx := testApex(t, `
186 apex {
187 name: "myapex",
188 key: "myapex.key",
189 native_shared_libs: ["mylib"],
190 }
191
192 apex_key {
193 name: "myapex.key",
194 public_key: "testkey.avbpubkey",
195 private_key: "testkey.pem",
196 }
197
198 cc_library {
199 name: "mylib",
200 srcs: ["mylib.cpp"],
201 shared_libs: ["mylib2"],
202 system_shared_libs: [],
203 stl: "none",
204 }
205
206 cc_library {
207 name: "mylib2",
208 srcs: ["mylib.cpp"],
209 system_shared_libs: [],
210 stl: "none",
211 }
212 `)
213
214 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
215 copyCmds := apexRule.Args["copy_commands"]
216
217 // Ensure that main rule creates an output
218 ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned")
219
220 // Ensure that apex variant is created for the direct dep
Jiyong Parkda6eb592018-12-19 17:12:36 +0900221 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900222
223 // Ensure that apex variant is created for the indirect dep
Jiyong Parkda6eb592018-12-19 17:12:36 +0900224 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared_myapex")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900225
226 // Ensure that both direct and indirect deps are copied into apex
Alex Light5098a612018-11-29 17:12:15 -0800227 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
228 ensureContains(t, copyCmds, "image.apex/lib64/mylib2.so")
229}
230
231func TestBasicZipApex(t *testing.T) {
232 ctx := testApex(t, `
233 apex {
234 name: "myapex",
235 key: "myapex.key",
236 payload_type: "zip",
237 native_shared_libs: ["mylib"],
238 }
239
240 apex_key {
241 name: "myapex.key",
242 public_key: "testkey.avbpubkey",
243 private_key: "testkey.pem",
244 }
245
246 cc_library {
247 name: "mylib",
248 srcs: ["mylib.cpp"],
249 shared_libs: ["mylib2"],
250 system_shared_libs: [],
251 stl: "none",
252 }
253
254 cc_library {
255 name: "mylib2",
256 srcs: ["mylib.cpp"],
257 system_shared_libs: [],
258 stl: "none",
259 }
260 `)
261
262 zipApexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("zipApexRule")
263 copyCmds := zipApexRule.Args["copy_commands"]
264
265 // Ensure that main rule creates an output
266 ensureContains(t, zipApexRule.Output.String(), "myapex.zipapex.unsigned")
267
268 // Ensure that APEX variant is created for the direct dep
Jiyong Parkda6eb592018-12-19 17:12:36 +0900269 ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex")
Alex Light5098a612018-11-29 17:12:15 -0800270
271 // Ensure that APEX variant is created for the indirect dep
Jiyong Parkda6eb592018-12-19 17:12:36 +0900272 ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared_myapex")
Alex Light5098a612018-11-29 17:12:15 -0800273
274 // Ensure that both direct and indirect deps are copied into apex
275 ensureContains(t, copyCmds, "image.zipapex/lib64/mylib.so")
276 ensureContains(t, copyCmds, "image.zipapex/lib64/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900277}
278
279func TestApexWithStubs(t *testing.T) {
280 ctx := testApex(t, `
281 apex {
282 name: "myapex",
283 key: "myapex.key",
284 native_shared_libs: ["mylib", "mylib3"],
285 }
286
287 apex_key {
288 name: "myapex.key",
289 public_key: "testkey.avbpubkey",
290 private_key: "testkey.pem",
291 }
292
293 cc_library {
294 name: "mylib",
295 srcs: ["mylib.cpp"],
296 shared_libs: ["mylib2", "mylib3"],
297 system_shared_libs: [],
298 stl: "none",
299 }
300
301 cc_library {
302 name: "mylib2",
303 srcs: ["mylib.cpp"],
Jiyong Park64379952018-12-13 18:37:29 +0900304 cflags: ["-include mylib.h"],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900305 system_shared_libs: [],
306 stl: "none",
307 stubs: {
308 versions: ["1", "2", "3"],
309 },
310 }
311
312 cc_library {
313 name: "mylib3",
Jiyong Park28d395a2018-12-07 22:42:47 +0900314 srcs: ["mylib.cpp"],
315 shared_libs: ["mylib4"],
316 system_shared_libs: [],
Jiyong Park25fc6a92018-11-18 18:02:45 +0900317 stl: "none",
318 stubs: {
319 versions: ["10", "11", "12"],
320 },
321 }
Jiyong Park28d395a2018-12-07 22:42:47 +0900322
323 cc_library {
324 name: "mylib4",
325 srcs: ["mylib.cpp"],
326 system_shared_libs: [],
327 stl: "none",
328 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900329 `)
330
331 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
332 copyCmds := apexRule.Args["copy_commands"]
333
334 // Ensure that direct non-stubs dep is always included
Alex Light5098a612018-11-29 17:12:15 -0800335 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900336
337 // Ensure that indirect stubs dep is not included
Alex Light5098a612018-11-29 17:12:15 -0800338 ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900339
340 // Ensure that direct stubs dep is included
Alex Light5098a612018-11-29 17:12:15 -0800341 ensureContains(t, copyCmds, "image.apex/lib64/mylib3.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900342
Jiyong Parkda6eb592018-12-19 17:12:36 +0900343 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_shared_myapex").Rule("ld").Args["libFlags"]
Jiyong Park25fc6a92018-11-18 18:02:45 +0900344
345 // Ensure that mylib is linking with the latest version of stubs for mylib2
Jiyong Parkda6eb592018-12-19 17:12:36 +0900346 ensureContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_core_shared_3_myapex/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900347 // ... and not linking to the non-stub (impl) variant of mylib2
Jiyong Parkda6eb592018-12-19 17:12:36 +0900348 ensureNotContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_core_shared_myapex/mylib2.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900349
350 // 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 +0900351 ensureContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_core_shared_myapex/mylib3.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900352 // .. and not linking to the stubs variant of mylib3
Jiyong Parkda6eb592018-12-19 17:12:36 +0900353 ensureNotContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_core_shared_12_myapex/mylib3.so")
Jiyong Park64379952018-12-13 18:37:29 +0900354
355 // Ensure that stubs libs are built without -include flags
Jiyong Parkda6eb592018-12-19 17:12:36 +0900356 mylib2Cflags := ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"]
Jiyong Park64379952018-12-13 18:37:29 +0900357 ensureNotContains(t, mylib2Cflags, "-include ")
Jiyong Park3fd0baf2018-12-07 16:25:39 +0900358
359 // Ensure that genstub is invoked with --apex
Jiyong Parkda6eb592018-12-19 17:12:36 +0900360 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 +0900361}
362
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900363func TestApexWithExplicitStubsDependency(t *testing.T) {
364 ctx := testApex(t, `
365 apex {
366 name: "myapex",
367 key: "myapex.key",
368 native_shared_libs: ["mylib"],
369 }
370
371 apex_key {
372 name: "myapex.key",
373 public_key: "testkey.avbpubkey",
374 private_key: "testkey.pem",
375 }
376
377 cc_library {
378 name: "mylib",
379 srcs: ["mylib.cpp"],
380 shared_libs: ["libfoo#10"],
381 system_shared_libs: [],
382 stl: "none",
383 }
384
385 cc_library {
386 name: "libfoo",
387 srcs: ["mylib.cpp"],
388 shared_libs: ["libbar"],
389 system_shared_libs: [],
390 stl: "none",
391 stubs: {
392 versions: ["10", "20", "30"],
393 },
394 }
395
396 cc_library {
397 name: "libbar",
398 srcs: ["mylib.cpp"],
399 system_shared_libs: [],
400 stl: "none",
401 }
402
403 `)
404
405 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
406 copyCmds := apexRule.Args["copy_commands"]
407
408 // Ensure that direct non-stubs dep is always included
409 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
410
411 // Ensure that indirect stubs dep is not included
412 ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so")
413
414 // Ensure that dependency of stubs is not included
415 ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so")
416
Jiyong Parkda6eb592018-12-19 17:12:36 +0900417 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_shared_myapex").Rule("ld").Args["libFlags"]
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900418
419 // Ensure that mylib is linking with version 10 of libfoo
Jiyong Parkda6eb592018-12-19 17:12:36 +0900420 ensureContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_core_shared_10_myapex/libfoo.so")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900421 // ... and not linking to the non-stub (impl) variant of libfoo
Jiyong Parkda6eb592018-12-19 17:12:36 +0900422 ensureNotContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_core_shared_myapex/libfoo.so")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900423
Jiyong Parkda6eb592018-12-19 17:12:36 +0900424 libFooStubsLdFlags := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_core_shared_10_myapex").Rule("ld").Args["libFlags"]
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900425
426 // Ensure that libfoo stubs is not linking to libbar (since it is a stubs)
427 ensureNotContains(t, libFooStubsLdFlags, "libbar.so")
428}
429
Jiyong Park25fc6a92018-11-18 18:02:45 +0900430func TestApexWithSystemLibsStubs(t *testing.T) {
431 ctx := testApex(t, `
432 apex {
433 name: "myapex",
434 key: "myapex.key",
435 native_shared_libs: ["mylib", "mylib_shared", "libdl", "libm"],
436 }
437
438 apex_key {
439 name: "myapex.key",
440 public_key: "testkey.avbpubkey",
441 private_key: "testkey.pem",
442 }
443
444 cc_library {
445 name: "mylib",
446 srcs: ["mylib.cpp"],
447 shared_libs: ["libdl#27"],
448 stl: "none",
449 }
450
451 cc_library_shared {
452 name: "mylib_shared",
453 srcs: ["mylib.cpp"],
454 shared_libs: ["libdl#27"],
455 stl: "none",
456 }
457
458 cc_library {
459 name: "libc",
460 no_libgcc: true,
461 nocrt: true,
462 system_shared_libs: [],
463 stl: "none",
464 stubs: {
465 versions: ["27", "28", "29"],
466 },
467 }
468
469 cc_library {
470 name: "libm",
471 no_libgcc: true,
472 nocrt: true,
473 system_shared_libs: [],
474 stl: "none",
475 stubs: {
476 versions: ["27", "28", "29"],
477 },
478 }
479
480 cc_library {
481 name: "libdl",
482 no_libgcc: true,
483 nocrt: true,
484 system_shared_libs: [],
485 stl: "none",
486 stubs: {
487 versions: ["27", "28", "29"],
488 },
489 }
490 `)
491
492 apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
493 copyCmds := apexRule.Args["copy_commands"]
494
495 // Ensure that mylib, libm, libdl are included.
Alex Light5098a612018-11-29 17:12:15 -0800496 ensureContains(t, copyCmds, "image.apex/lib64/mylib.so")
497 ensureContains(t, copyCmds, "image.apex/lib64/libm.so")
498 ensureContains(t, copyCmds, "image.apex/lib64/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900499
500 // Ensure that libc is not included (since it has stubs and not listed in native_shared_libs)
Alex Light5098a612018-11-29 17:12:15 -0800501 ensureNotContains(t, copyCmds, "image.apex/lib64/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900502
Jiyong Parkda6eb592018-12-19 17:12:36 +0900503 mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_shared_myapex").Rule("ld").Args["libFlags"]
504 mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"]
505 mylibSharedCFlags := ctx.ModuleForTests("mylib_shared", "android_arm64_armv8-a_core_shared_myapex").Rule("cc").Args["cFlags"]
Jiyong Park25fc6a92018-11-18 18:02:45 +0900506
507 // For dependency to libc
508 // Ensure that mylib is linking with the latest version of stubs
Jiyong Parkda6eb592018-12-19 17:12:36 +0900509 ensureContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_core_shared_29_myapex/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900510 // ... and not linking to the non-stub (impl) variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900511 ensureNotContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_core_shared_myapex/libc.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900512 // ... Cflags from stub is correctly exported to mylib
513 ensureContains(t, mylibCFlags, "__LIBC_API__=29")
514 ensureContains(t, mylibSharedCFlags, "__LIBC_API__=29")
515
516 // For dependency to libm
517 // Ensure that mylib is linking with the non-stub (impl) variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900518 ensureContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_core_shared_myapex/libm.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900519 // ... and not linking to the stub variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900520 ensureNotContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_core_shared_29_myapex/libm.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900521 // ... and is not compiling with the stub
522 ensureNotContains(t, mylibCFlags, "__LIBM_API__=29")
523 ensureNotContains(t, mylibSharedCFlags, "__LIBM_API__=29")
524
525 // For dependency to libdl
526 // Ensure that mylib is linking with the specified version of stubs
Jiyong Parkda6eb592018-12-19 17:12:36 +0900527 ensureContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_27_myapex/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900528 // ... and not linking to the other versions of stubs
Jiyong Parkda6eb592018-12-19 17:12:36 +0900529 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_28_myapex/libdl.so")
530 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_29_myapex/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900531 // ... and not linking to the non-stub (impl) variant
Jiyong Parkda6eb592018-12-19 17:12:36 +0900532 ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_myapex/libdl.so")
Jiyong Park25fc6a92018-11-18 18:02:45 +0900533 // ... Cflags from stub is correctly exported to mylib
534 ensureContains(t, mylibCFlags, "__LIBDL_API__=27")
535 ensureContains(t, mylibSharedCFlags, "__LIBDL_API__=27")
536}
Jiyong Park7c2ee712018-12-07 00:42:25 +0900537
538func TestFilesInSubDir(t *testing.T) {
539 ctx := testApex(t, `
540 apex {
541 name: "myapex",
542 key: "myapex.key",
543 prebuilts: ["myetc"],
544 }
545
546 apex_key {
547 name: "myapex.key",
548 public_key: "testkey.avbpubkey",
549 private_key: "testkey.pem",
550 }
551
552 prebuilt_etc {
553 name: "myetc",
554 src: "myprebuilt",
555 sub_dir: "foo/bar",
556 }
557 `)
558
559 generateFsRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("generateFsConfig")
560 dirs := strings.Split(generateFsRule.Args["exec_paths"], " ")
561
562 // Ensure that etc, etc/foo, and etc/foo/bar are all listed
563 ensureListContains(t, dirs, "etc")
564 ensureListContains(t, dirs, "etc/foo")
565 ensureListContains(t, dirs, "etc/foo/bar")
566}
Jiyong Parkda6eb592018-12-19 17:12:36 +0900567
568func TestUseVendor(t *testing.T) {
569 ctx := testApex(t, `
570 apex {
571 name: "myapex",
572 key: "myapex.key",
573 native_shared_libs: ["mylib"],
574 use_vendor: true,
575 }
576
577 apex_key {
578 name: "myapex.key",
579 public_key: "testkey.avbpubkey",
580 private_key: "testkey.pem",
581 }
582
583 cc_library {
584 name: "mylib",
585 srcs: ["mylib.cpp"],
586 shared_libs: ["mylib2"],
587 system_shared_libs: [],
588 vendor_available: true,
589 stl: "none",
590 }
591
592 cc_library {
593 name: "mylib2",
594 srcs: ["mylib.cpp"],
595 system_shared_libs: [],
596 vendor_available: true,
597 stl: "none",
598 }
599 `)
600
601 inputsList := []string{}
602 for _, i := range ctx.ModuleForTests("myapex", "android_common_myapex").Module().BuildParamsForTests() {
603 for _, implicit := range i.Implicits {
604 inputsList = append(inputsList, implicit.String())
605 }
606 }
607 inputsString := strings.Join(inputsList, " ")
608
609 // ensure that the apex includes vendor variants of the direct and indirect deps
610 ensureContains(t, inputsString, "android_arm64_armv8-a_vendor_shared_myapex/mylib.so")
611 ensureContains(t, inputsString, "android_arm64_armv8-a_vendor_shared_myapex/mylib2.so")
612
613 // ensure that the apex does not include core variants
614 ensureNotContains(t, inputsString, "android_arm64_armv8-a_core_shared_myapex/mylib.so")
615 ensureNotContains(t, inputsString, "android_arm64_armv8-a_core_shared_myapex/mylib2.so")
616}