blob: dc23620e79f605d6f81ed11e6943a3d2f4c63bdc [file] [log] [blame]
Colin Crossd00350c2017-11-17 10:55:38 -08001// Copyright 2017 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
Colin Cross74d1ec02015-04-28 13:30:13 -070015package cc
16
17import (
Colin Cross5b529592017-05-09 13:34:34 -070018 "android/soong/android"
Colin Crossf18e1102017-11-16 14:33:08 -080019
Jeff Gaston294356f2017-09-27 17:05:30 -070020 "fmt"
Jiyong Park6a43f042017-10-12 23:05:00 +090021 "io/ioutil"
22 "os"
Colin Cross74d1ec02015-04-28 13:30:13 -070023 "reflect"
Jeff Gaston294356f2017-09-27 17:05:30 -070024 "sort"
25 "strings"
Colin Cross74d1ec02015-04-28 13:30:13 -070026 "testing"
27)
28
Jiyong Park6a43f042017-10-12 23:05:00 +090029var buildDir string
30
31func setUp() {
32 var err error
33 buildDir, err = ioutil.TempDir("", "soong_cc_test")
34 if err != nil {
35 panic(err)
36 }
37}
38
39func tearDown() {
40 os.RemoveAll(buildDir)
41}
42
43func TestMain(m *testing.M) {
44 run := func() int {
45 setUp()
46 defer tearDown()
47
48 return m.Run()
49 }
50
51 os.Exit(run())
52}
53
Doug Hornc32c6b02019-01-17 14:44:05 -080054func gatherRequiredDeps(os android.OsType) string {
55 ret := `
Jeff Gaston294356f2017-09-27 17:05:30 -070056 toolchain_library {
57 name: "libatomic",
58 vendor_available: true,
Jiyong Park37b25202018-07-11 10:49:27 +090059 recovery_available: true,
Dan Willemsenfeea4df2018-10-07 18:16:48 -070060 src: "",
Jeff Gaston294356f2017-09-27 17:05:30 -070061 }
62
63 toolchain_library {
64 name: "libcompiler_rt-extras",
65 vendor_available: true,
Jiyong Park37b25202018-07-11 10:49:27 +090066 recovery_available: true,
Dan Willemsenfeea4df2018-10-07 18:16:48 -070067 src: "",
Jeff Gaston294356f2017-09-27 17:05:30 -070068 }
69
70 toolchain_library {
Yi Kong7df0f302018-10-08 22:10:12 +000071 name: "libclang_rt.builtins-arm-android",
72 vendor_available: true,
73 recovery_available: true,
74 src: "",
75 }
76
77 toolchain_library {
78 name: "libclang_rt.builtins-aarch64-android",
79 vendor_available: true,
80 recovery_available: true,
81 src: "",
82 }
83
84 toolchain_library {
85 name: "libclang_rt.builtins-i686-android",
86 vendor_available: true,
87 recovery_available: true,
88 src: "",
89 }
90
91 toolchain_library {
92 name: "libclang_rt.builtins-x86_64-android",
93 vendor_available: true,
94 recovery_available: true,
95 src: "",
96 }
97
98 toolchain_library {
Jeff Gaston294356f2017-09-27 17:05:30 -070099 name: "libgcc",
100 vendor_available: true,
Jiyong Park37b25202018-07-11 10:49:27 +0900101 recovery_available: true,
Dan Willemsenfeea4df2018-10-07 18:16:48 -0700102 src: "",
Jeff Gaston294356f2017-09-27 17:05:30 -0700103 }
104
105 cc_library {
106 name: "libc",
Logan Chienf3511742017-10-31 18:04:35 +0800107 no_libgcc: true,
108 nocrt: true,
Jeff Gaston294356f2017-09-27 17:05:30 -0700109 system_shared_libs: [],
Jiyong Park37b25202018-07-11 10:49:27 +0900110 recovery_available: true,
Jeff Gaston294356f2017-09-27 17:05:30 -0700111 }
112 llndk_library {
113 name: "libc",
114 symbol_file: "",
115 }
116 cc_library {
117 name: "libm",
Logan Chienf3511742017-10-31 18:04:35 +0800118 no_libgcc: true,
119 nocrt: true,
Jeff Gaston294356f2017-09-27 17:05:30 -0700120 system_shared_libs: [],
Jiyong Park37b25202018-07-11 10:49:27 +0900121 recovery_available: true,
Jeff Gaston294356f2017-09-27 17:05:30 -0700122 }
123 llndk_library {
124 name: "libm",
125 symbol_file: "",
126 }
127 cc_library {
128 name: "libdl",
Logan Chienf3511742017-10-31 18:04:35 +0800129 no_libgcc: true,
130 nocrt: true,
Jeff Gaston294356f2017-09-27 17:05:30 -0700131 system_shared_libs: [],
Jiyong Park37b25202018-07-11 10:49:27 +0900132 recovery_available: true,
Jeff Gaston294356f2017-09-27 17:05:30 -0700133 }
134 llndk_library {
135 name: "libdl",
136 symbol_file: "",
137 }
Jaewoong Jung3e6b1fb2018-11-02 22:56:30 +0000138 cc_library {
Jiyong Park374510b2018-03-19 18:23:01 +0900139 name: "libc++_static",
140 no_libgcc: true,
141 nocrt: true,
142 system_shared_libs: [],
143 stl: "none",
144 vendor_available: true,
Jiyong Park37b25202018-07-11 10:49:27 +0900145 recovery_available: true,
Jiyong Park374510b2018-03-19 18:23:01 +0900146 }
147 cc_library {
148 name: "libc++",
149 no_libgcc: true,
150 nocrt: true,
151 system_shared_libs: [],
152 stl: "none",
153 vendor_available: true,
Jiyong Park37b25202018-07-11 10:49:27 +0900154 recovery_available: true,
Jiyong Park374510b2018-03-19 18:23:01 +0900155 vndk: {
156 enabled: true,
157 support_system_process: true,
158 },
159 }
160 cc_library {
161 name: "libunwind_llvm",
162 no_libgcc: true,
163 nocrt: true,
164 system_shared_libs: [],
165 stl: "none",
166 vendor_available: true,
Jiyong Park37b25202018-07-11 10:49:27 +0900167 recovery_available: true,
Jiyong Park374510b2018-03-19 18:23:01 +0900168 }
Jeff Gaston294356f2017-09-27 17:05:30 -0700169
170 cc_object {
171 name: "crtbegin_so",
Jiyong Park37b25202018-07-11 10:49:27 +0900172 recovery_available: true,
Jiyong Park5baac542018-08-28 09:55:37 +0900173 vendor_available: true,
Jeff Gaston294356f2017-09-27 17:05:30 -0700174 }
175
176 cc_object {
Jaewoong Jung232c07c2018-12-18 11:08:25 -0800177 name: "crtbegin_static",
178 recovery_available: true,
179 vendor_available: true,
180 }
181
182 cc_object {
Jeff Gaston294356f2017-09-27 17:05:30 -0700183 name: "crtend_so",
Jiyong Park37b25202018-07-11 10:49:27 +0900184 recovery_available: true,
Jiyong Park5baac542018-08-28 09:55:37 +0900185 vendor_available: true,
Jeff Gaston294356f2017-09-27 17:05:30 -0700186 }
187
Jaewoong Jung232c07c2018-12-18 11:08:25 -0800188 cc_object {
189 name: "crtend_android",
190 recovery_available: true,
191 vendor_available: true,
192 }
193
Colin Crossad59e752017-11-16 14:29:11 -0800194 cc_library {
195 name: "libprotobuf-cpp-lite",
196 }
Doug Hornc32c6b02019-01-17 14:44:05 -0800197 `
198 if os == android.Fuchsia {
199 ret += `
200 cc_library {
201 name: "libbioniccompat",
202 stl: "none",
203 }
204 cc_library {
205 name: "libcompiler_rt",
206 stl: "none",
207 }
208 `
209 }
210 return ret
211}
Colin Crossad59e752017-11-16 14:29:11 -0800212
Doug Hornc32c6b02019-01-17 14:44:05 -0800213func createTestContext(t *testing.T, config android.Config, bp string, os android.OsType) *android.TestContext {
214 ctx := android.NewTestArchContext()
215 ctx.RegisterModuleType("cc_binary", android.ModuleFactoryAdaptor(BinaryFactory))
216 ctx.RegisterModuleType("cc_library", android.ModuleFactoryAdaptor(LibraryFactory))
217 ctx.RegisterModuleType("cc_library_shared", android.ModuleFactoryAdaptor(LibrarySharedFactory))
218 ctx.RegisterModuleType("cc_library_headers", android.ModuleFactoryAdaptor(LibraryHeaderFactory))
219 ctx.RegisterModuleType("toolchain_library", android.ModuleFactoryAdaptor(ToolchainLibraryFactory))
220 ctx.RegisterModuleType("llndk_library", android.ModuleFactoryAdaptor(LlndkLibraryFactory))
221 ctx.RegisterModuleType("llndk_headers", android.ModuleFactoryAdaptor(llndkHeadersFactory))
222 ctx.RegisterModuleType("vendor_public_library", android.ModuleFactoryAdaptor(vendorPublicLibraryFactory))
223 ctx.RegisterModuleType("cc_object", android.ModuleFactoryAdaptor(ObjectFactory))
224 ctx.RegisterModuleType("filegroup", android.ModuleFactoryAdaptor(android.FileGroupFactory))
225 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
226 ctx.BottomUp("image", ImageMutator).Parallel()
227 ctx.BottomUp("link", LinkageMutator).Parallel()
228 ctx.BottomUp("vndk", VndkMutator).Parallel()
229 ctx.BottomUp("version", VersionMutator).Parallel()
230 ctx.BottomUp("begin", BeginMutator).Parallel()
231 })
232 ctx.Register()
233
234 // add some modules that are required by the compiler and/or linker
235 bp = bp + gatherRequiredDeps(os)
Jeff Gaston294356f2017-09-27 17:05:30 -0700236
Jiyong Park6a43f042017-10-12 23:05:00 +0900237 ctx.MockFileSystem(map[string][]byte{
Jiyong Park7ed9de32018-10-15 22:25:07 +0900238 "Android.bp": []byte(bp),
239 "foo.c": nil,
240 "bar.c": nil,
241 "a.proto": nil,
242 "b.aidl": nil,
243 "my_include": nil,
244 "foo.map.txt": nil,
Jiyong Park6a43f042017-10-12 23:05:00 +0900245 })
246
Logan Chienf3511742017-10-31 18:04:35 +0800247 return ctx
248}
249
250func testCcWithConfig(t *testing.T, bp string, config android.Config) *android.TestContext {
Doug Hornc32c6b02019-01-17 14:44:05 -0800251 return testCcWithConfigForOs(t, bp, config, android.Android)
252}
253
254func testCcWithConfigForOs(t *testing.T, bp string, config android.Config, os android.OsType) *android.TestContext {
Logan Chiend3c59a22018-03-29 14:08:15 +0800255 t.Helper()
Doug Hornc32c6b02019-01-17 14:44:05 -0800256 ctx := createTestContext(t, config, bp, os)
Logan Chienf3511742017-10-31 18:04:35 +0800257
Jeff Gastond3e141d2017-08-08 17:46:01 -0700258 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
Logan Chien42039712018-03-12 16:29:17 +0800259 android.FailIfErrored(t, errs)
Jiyong Park6a43f042017-10-12 23:05:00 +0900260 _, errs = ctx.PrepareBuildActions(config)
Logan Chien42039712018-03-12 16:29:17 +0800261 android.FailIfErrored(t, errs)
Jiyong Park6a43f042017-10-12 23:05:00 +0900262
263 return ctx
264}
265
Logan Chienf3511742017-10-31 18:04:35 +0800266func testCc(t *testing.T, bp string) *android.TestContext {
Logan Chiend3c59a22018-03-29 14:08:15 +0800267 t.Helper()
Logan Chienf3511742017-10-31 18:04:35 +0800268 config := android.TestArchConfig(buildDir, nil)
Dan Willemsen674dc7f2018-03-12 18:06:05 -0700269 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
270 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
Logan Chienf3511742017-10-31 18:04:35 +0800271
272 return testCcWithConfig(t, bp, config)
273}
274
275func testCcNoVndk(t *testing.T, bp string) *android.TestContext {
Logan Chiend3c59a22018-03-29 14:08:15 +0800276 t.Helper()
Logan Chienf3511742017-10-31 18:04:35 +0800277 config := android.TestArchConfig(buildDir, nil)
Dan Willemsen674dc7f2018-03-12 18:06:05 -0700278 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
Logan Chienf3511742017-10-31 18:04:35 +0800279
280 return testCcWithConfig(t, bp, config)
281}
282
283func testCcError(t *testing.T, pattern string, bp string) {
Logan Chiend3c59a22018-03-29 14:08:15 +0800284 t.Helper()
Logan Chienf3511742017-10-31 18:04:35 +0800285 config := android.TestArchConfig(buildDir, nil)
Dan Willemsen674dc7f2018-03-12 18:06:05 -0700286 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
287 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
Logan Chienf3511742017-10-31 18:04:35 +0800288
Doug Hornc32c6b02019-01-17 14:44:05 -0800289 ctx := createTestContext(t, config, bp, android.Android)
Logan Chienf3511742017-10-31 18:04:35 +0800290
291 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
292 if len(errs) > 0 {
Logan Chienee97c3e2018-03-12 16:34:26 +0800293 android.FailIfNoMatchingErrors(t, pattern, errs)
Logan Chienf3511742017-10-31 18:04:35 +0800294 return
295 }
296
297 _, errs = ctx.PrepareBuildActions(config)
298 if len(errs) > 0 {
Logan Chienee97c3e2018-03-12 16:34:26 +0800299 android.FailIfNoMatchingErrors(t, pattern, errs)
Logan Chienf3511742017-10-31 18:04:35 +0800300 return
301 }
302
303 t.Fatalf("missing expected error %q (0 errors are returned)", pattern)
304}
305
306const (
Jiyong Park5baac542018-08-28 09:55:37 +0900307 coreVariant = "android_arm64_armv8-a_core_shared"
308 vendorVariant = "android_arm64_armv8-a_vendor_shared"
309 recoveryVariant = "android_arm64_armv8-a_recovery_shared"
Logan Chienf3511742017-10-31 18:04:35 +0800310)
311
Doug Hornc32c6b02019-01-17 14:44:05 -0800312func TestFuchsiaDeps(t *testing.T) {
313 t.Helper()
314
315 bp := `
316 cc_library {
317 name: "libTest",
318 srcs: ["foo.c"],
319 target: {
320 fuchsia: {
321 srcs: ["bar.c"],
322 },
323 },
324 }`
325
326 config := android.TestArchConfigFuchsia(buildDir, nil)
327 ctx := testCcWithConfigForOs(t, bp, config, android.Fuchsia)
328
329 rt := false
330 fb := false
331
332 ld := ctx.ModuleForTests("libTest", "fuchsia_arm64_shared").Rule("ld")
333 implicits := ld.Implicits
334 for _, lib := range implicits {
335 if strings.Contains(lib.Rel(), "libcompiler_rt") {
336 rt = true
337 }
338
339 if strings.Contains(lib.Rel(), "libbioniccompat") {
340 fb = true
341 }
342 }
343
344 if !rt || !fb {
345 t.Errorf("fuchsia libs must link libcompiler_rt and libbioniccompat")
346 }
347}
348
349func TestFuchsiaTargetDecl(t *testing.T) {
350 t.Helper()
351
352 bp := `
353 cc_library {
354 name: "libTest",
355 srcs: ["foo.c"],
356 target: {
357 fuchsia: {
358 srcs: ["bar.c"],
359 },
360 },
361 }`
362
363 config := android.TestArchConfigFuchsia(buildDir, nil)
364 ctx := testCcWithConfigForOs(t, bp, config, android.Fuchsia)
365 ld := ctx.ModuleForTests("libTest", "fuchsia_arm64_shared").Rule("ld")
366 var objs []string
367 for _, o := range ld.Inputs {
368 objs = append(objs, o.Base())
369 }
370 if len(objs) != 2 || objs[0] != "foo.o" || objs[1] != "bar.o" {
371 t.Errorf("inputs of libTest must be []string{\"foo.o\", \"bar.o\"}, but was %#v.", objs)
372 }
373}
374
Jiyong Park6a43f042017-10-12 23:05:00 +0900375func TestVendorSrc(t *testing.T) {
376 ctx := testCc(t, `
377 cc_library {
378 name: "libTest",
379 srcs: ["foo.c"],
Logan Chienf3511742017-10-31 18:04:35 +0800380 no_libgcc: true,
381 nocrt: true,
382 system_shared_libs: [],
Jiyong Park6a43f042017-10-12 23:05:00 +0900383 vendor_available: true,
384 target: {
385 vendor: {
386 srcs: ["bar.c"],
387 },
388 },
389 }
Jiyong Park6a43f042017-10-12 23:05:00 +0900390 `)
391
Logan Chienf3511742017-10-31 18:04:35 +0800392 ld := ctx.ModuleForTests("libTest", vendorVariant).Rule("ld")
Jiyong Park6a43f042017-10-12 23:05:00 +0900393 var objs []string
394 for _, o := range ld.Inputs {
395 objs = append(objs, o.Base())
396 }
Colin Cross95d33fe2018-01-03 13:40:46 -0800397 if len(objs) != 2 || objs[0] != "foo.o" || objs[1] != "bar.o" {
Jiyong Park6a43f042017-10-12 23:05:00 +0900398 t.Errorf("inputs of libTest must be []string{\"foo.o\", \"bar.o\"}, but was %#v.", objs)
399 }
400}
401
Logan Chienf3511742017-10-31 18:04:35 +0800402func checkVndkModule(t *testing.T, ctx *android.TestContext, name, subDir string,
403 isVndkSp bool, extends string) {
404
Logan Chiend3c59a22018-03-29 14:08:15 +0800405 t.Helper()
406
Logan Chienf3511742017-10-31 18:04:35 +0800407 mod := ctx.ModuleForTests(name, vendorVariant).Module().(*Module)
408 if !mod.hasVendorVariant() {
Colin Crossf46e37f2018-03-21 16:25:58 -0700409 t.Errorf("%q must have vendor variant", name)
Logan Chienf3511742017-10-31 18:04:35 +0800410 }
411
412 // Check library properties.
413 lib, ok := mod.compiler.(*libraryDecorator)
414 if !ok {
415 t.Errorf("%q must have libraryDecorator", name)
416 } else if lib.baseInstaller.subDir != subDir {
417 t.Errorf("%q must use %q as subdir but it is using %q", name, subDir,
418 lib.baseInstaller.subDir)
419 }
420
421 // Check VNDK properties.
422 if mod.vndkdep == nil {
423 t.Fatalf("%q must have `vndkdep`", name)
424 }
425 if !mod.isVndk() {
426 t.Errorf("%q isVndk() must equal to true", name)
427 }
428 if mod.isVndkSp() != isVndkSp {
429 t.Errorf("%q isVndkSp() must equal to %t", name, isVndkSp)
430 }
431
432 // Check VNDK extension properties.
433 isVndkExt := extends != ""
434 if mod.isVndkExt() != isVndkExt {
435 t.Errorf("%q isVndkExt() must equal to %t", name, isVndkExt)
436 }
437
438 if actualExtends := mod.getVndkExtendsModuleName(); actualExtends != extends {
439 t.Errorf("%q must extend from %q but get %q", name, extends, actualExtends)
440 }
441}
442
443func TestVndk(t *testing.T) {
444 ctx := testCc(t, `
445 cc_library {
446 name: "libvndk",
447 vendor_available: true,
448 vndk: {
449 enabled: true,
450 },
451 nocrt: true,
452 }
453
454 cc_library {
455 name: "libvndk_private",
456 vendor_available: false,
457 vndk: {
458 enabled: true,
459 },
460 nocrt: true,
461 }
462
463 cc_library {
464 name: "libvndk_sp",
465 vendor_available: true,
466 vndk: {
467 enabled: true,
468 support_system_process: true,
469 },
470 nocrt: true,
471 }
472
473 cc_library {
474 name: "libvndk_sp_private",
475 vendor_available: false,
476 vndk: {
477 enabled: true,
478 support_system_process: true,
479 },
480 nocrt: true,
481 }
482 `)
483
484 checkVndkModule(t, ctx, "libvndk", "vndk-VER", false, "")
485 checkVndkModule(t, ctx, "libvndk_private", "vndk-VER", false, "")
486 checkVndkModule(t, ctx, "libvndk_sp", "vndk-sp-VER", true, "")
487 checkVndkModule(t, ctx, "libvndk_sp_private", "vndk-sp-VER", true, "")
488}
489
Logan Chiend3c59a22018-03-29 14:08:15 +0800490func TestVndkDepError(t *testing.T) {
491 // Check whether an error is emitted when a VNDK lib depends on a system lib.
492 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
493 cc_library {
494 name: "libvndk",
495 vendor_available: true,
496 vndk: {
497 enabled: true,
498 },
499 shared_libs: ["libfwk"], // Cause error
500 nocrt: true,
501 }
502
503 cc_library {
504 name: "libfwk",
505 nocrt: true,
506 }
507 `)
508
509 // Check whether an error is emitted when a VNDK lib depends on a vendor lib.
510 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
511 cc_library {
512 name: "libvndk",
513 vendor_available: true,
514 vndk: {
515 enabled: true,
516 },
517 shared_libs: ["libvendor"], // Cause error
518 nocrt: true,
519 }
520
521 cc_library {
522 name: "libvendor",
523 vendor: true,
524 nocrt: true,
525 }
526 `)
527
528 // Check whether an error is emitted when a VNDK-SP lib depends on a system lib.
529 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
530 cc_library {
531 name: "libvndk_sp",
532 vendor_available: true,
533 vndk: {
534 enabled: true,
535 support_system_process: true,
536 },
537 shared_libs: ["libfwk"], // Cause error
538 nocrt: true,
539 }
540
541 cc_library {
542 name: "libfwk",
543 nocrt: true,
544 }
545 `)
546
547 // Check whether an error is emitted when a VNDK-SP lib depends on a vendor lib.
548 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
549 cc_library {
550 name: "libvndk_sp",
551 vendor_available: true,
552 vndk: {
553 enabled: true,
554 support_system_process: true,
555 },
556 shared_libs: ["libvendor"], // Cause error
557 nocrt: true,
558 }
559
560 cc_library {
561 name: "libvendor",
562 vendor: true,
563 nocrt: true,
564 }
565 `)
566
567 // Check whether an error is emitted when a VNDK-SP lib depends on a VNDK lib.
568 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
569 cc_library {
570 name: "libvndk_sp",
571 vendor_available: true,
572 vndk: {
573 enabled: true,
574 support_system_process: true,
575 },
576 shared_libs: ["libvndk"], // Cause error
577 nocrt: true,
578 }
579
580 cc_library {
581 name: "libvndk",
582 vendor_available: true,
583 vndk: {
584 enabled: true,
585 },
586 nocrt: true,
587 }
588 `)
589}
590
Justin Yun9357f4a2018-11-28 15:14:47 +0900591func TestVndkMustNotBeProductSpecific(t *testing.T) {
592 // Check whether an error is emitted when a vndk lib has 'product_specific: true'.
593 testCcError(t, "product_specific must not be true when `vndk: {enabled: true}`", `
594 cc_library {
595 name: "libvndk",
596 product_specific: true, // Cause error
597 vendor_available: true,
598 vndk: {
599 enabled: true,
600 },
601 nocrt: true,
602 }
603 `)
604}
605
Logan Chienf3511742017-10-31 18:04:35 +0800606func TestVndkExt(t *testing.T) {
607 // This test checks the VNDK-Ext properties.
608 ctx := testCc(t, `
609 cc_library {
610 name: "libvndk",
611 vendor_available: true,
612 vndk: {
613 enabled: true,
614 },
615 nocrt: true,
616 }
617
618 cc_library {
619 name: "libvndk_ext",
620 vendor: true,
621 vndk: {
622 enabled: true,
623 extends: "libvndk",
624 },
625 nocrt: true,
626 }
627 `)
628
629 checkVndkModule(t, ctx, "libvndk_ext", "vndk", false, "libvndk")
630}
631
Logan Chiend3c59a22018-03-29 14:08:15 +0800632func TestVndkExtWithoutBoardVndkVersion(t *testing.T) {
Logan Chienf3511742017-10-31 18:04:35 +0800633 // This test checks the VNDK-Ext properties when BOARD_VNDK_VERSION is not set.
634 ctx := testCcNoVndk(t, `
635 cc_library {
636 name: "libvndk",
637 vendor_available: true,
638 vndk: {
639 enabled: true,
640 },
641 nocrt: true,
642 }
643
644 cc_library {
645 name: "libvndk_ext",
646 vendor: true,
647 vndk: {
648 enabled: true,
649 extends: "libvndk",
650 },
651 nocrt: true,
652 }
653 `)
654
655 // Ensures that the core variant of "libvndk_ext" can be found.
656 mod := ctx.ModuleForTests("libvndk_ext", coreVariant).Module().(*Module)
657 if extends := mod.getVndkExtendsModuleName(); extends != "libvndk" {
658 t.Errorf("\"libvndk_ext\" must extend from \"libvndk\" but get %q", extends)
659 }
660}
661
662func TestVndkExtError(t *testing.T) {
663 // This test ensures an error is emitted in ill-formed vndk-ext definition.
664 testCcError(t, "must set `vendor: true` to set `extends: \".*\"`", `
665 cc_library {
666 name: "libvndk",
667 vendor_available: true,
668 vndk: {
669 enabled: true,
670 },
671 nocrt: true,
672 }
673
674 cc_library {
675 name: "libvndk_ext",
676 vndk: {
677 enabled: true,
678 extends: "libvndk",
679 },
680 nocrt: true,
681 }
682 `)
683
684 testCcError(t, "must set `extends: \"\\.\\.\\.\"` to vndk extension", `
685 cc_library {
686 name: "libvndk",
687 vendor_available: true,
688 vndk: {
689 enabled: true,
690 },
691 nocrt: true,
692 }
693
694 cc_library {
695 name: "libvndk_ext",
696 vendor: true,
697 vndk: {
698 enabled: true,
699 },
700 nocrt: true,
701 }
702 `)
703}
704
705func TestVndkExtInconsistentSupportSystemProcessError(t *testing.T) {
706 // This test ensures an error is emitted for inconsistent support_system_process.
707 testCcError(t, "module \".*\" with mismatched support_system_process", `
708 cc_library {
709 name: "libvndk",
710 vendor_available: true,
711 vndk: {
712 enabled: true,
713 },
714 nocrt: true,
715 }
716
717 cc_library {
718 name: "libvndk_sp_ext",
719 vendor: true,
720 vndk: {
721 enabled: true,
722 extends: "libvndk",
723 support_system_process: true,
724 },
725 nocrt: true,
726 }
727 `)
728
729 testCcError(t, "module \".*\" with mismatched support_system_process", `
730 cc_library {
731 name: "libvndk_sp",
732 vendor_available: true,
733 vndk: {
734 enabled: true,
735 support_system_process: true,
736 },
737 nocrt: true,
738 }
739
740 cc_library {
741 name: "libvndk_ext",
742 vendor: true,
743 vndk: {
744 enabled: true,
745 extends: "libvndk_sp",
746 },
747 nocrt: true,
748 }
749 `)
750}
751
752func TestVndkExtVendorAvailableFalseError(t *testing.T) {
Logan Chiend3c59a22018-03-29 14:08:15 +0800753 // This test ensures an error is emitted when a VNDK-Ext library extends a VNDK library
Logan Chienf3511742017-10-31 18:04:35 +0800754 // with `vendor_available: false`.
755 testCcError(t, "`extends` refers module \".*\" which does not have `vendor_available: true`", `
756 cc_library {
757 name: "libvndk",
758 vendor_available: false,
759 vndk: {
760 enabled: true,
761 },
762 nocrt: true,
763 }
764
765 cc_library {
766 name: "libvndk_ext",
767 vendor: true,
768 vndk: {
769 enabled: true,
770 extends: "libvndk",
771 },
772 nocrt: true,
773 }
774 `)
775}
776
Logan Chiend3c59a22018-03-29 14:08:15 +0800777func TestVendorModuleUseVndkExt(t *testing.T) {
778 // This test ensures a vendor module can depend on a VNDK-Ext library.
Logan Chienf3511742017-10-31 18:04:35 +0800779 testCc(t, `
780 cc_library {
781 name: "libvndk",
782 vendor_available: true,
783 vndk: {
784 enabled: true,
785 },
786 nocrt: true,
787 }
788
789 cc_library {
790 name: "libvndk_ext",
791 vendor: true,
792 vndk: {
793 enabled: true,
794 extends: "libvndk",
795 },
796 nocrt: true,
797 }
798
799 cc_library {
800
801 name: "libvndk_sp",
802 vendor_available: true,
803 vndk: {
804 enabled: true,
805 support_system_process: true,
806 },
807 nocrt: true,
808 }
809
810 cc_library {
811 name: "libvndk_sp_ext",
812 vendor: true,
813 vndk: {
814 enabled: true,
815 extends: "libvndk_sp",
816 support_system_process: true,
817 },
818 nocrt: true,
819 }
820
821 cc_library {
822 name: "libvendor",
823 vendor: true,
824 shared_libs: ["libvndk_ext", "libvndk_sp_ext"],
825 nocrt: true,
826 }
827 `)
828}
829
Logan Chiend3c59a22018-03-29 14:08:15 +0800830func TestVndkExtUseVendorLib(t *testing.T) {
831 // This test ensures a VNDK-Ext library can depend on a vendor library.
Logan Chienf3511742017-10-31 18:04:35 +0800832 testCc(t, `
833 cc_library {
834 name: "libvndk",
835 vendor_available: true,
836 vndk: {
837 enabled: true,
838 },
839 nocrt: true,
840 }
841
842 cc_library {
843 name: "libvndk_ext",
844 vendor: true,
845 vndk: {
846 enabled: true,
847 extends: "libvndk",
848 },
849 shared_libs: ["libvendor"],
850 nocrt: true,
851 }
852
853 cc_library {
854 name: "libvendor",
855 vendor: true,
856 nocrt: true,
857 }
858 `)
Logan Chienf3511742017-10-31 18:04:35 +0800859
Logan Chiend3c59a22018-03-29 14:08:15 +0800860 // This test ensures a VNDK-SP-Ext library can depend on a vendor library.
861 testCc(t, `
Logan Chienf3511742017-10-31 18:04:35 +0800862 cc_library {
863 name: "libvndk_sp",
864 vendor_available: true,
865 vndk: {
866 enabled: true,
867 support_system_process: true,
868 },
869 nocrt: true,
870 }
871
872 cc_library {
873 name: "libvndk_sp_ext",
874 vendor: true,
875 vndk: {
876 enabled: true,
877 extends: "libvndk_sp",
878 support_system_process: true,
879 },
880 shared_libs: ["libvendor"], // Cause an error
881 nocrt: true,
882 }
883
884 cc_library {
885 name: "libvendor",
886 vendor: true,
887 nocrt: true,
888 }
889 `)
890}
891
Logan Chiend3c59a22018-03-29 14:08:15 +0800892func TestVndkSpExtUseVndkError(t *testing.T) {
893 // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK
894 // library.
895 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
896 cc_library {
897 name: "libvndk",
898 vendor_available: true,
899 vndk: {
900 enabled: true,
901 },
902 nocrt: true,
903 }
904
905 cc_library {
906 name: "libvndk_sp",
907 vendor_available: true,
908 vndk: {
909 enabled: true,
910 support_system_process: true,
911 },
912 nocrt: true,
913 }
914
915 cc_library {
916 name: "libvndk_sp_ext",
917 vendor: true,
918 vndk: {
919 enabled: true,
920 extends: "libvndk_sp",
921 support_system_process: true,
922 },
923 shared_libs: ["libvndk"], // Cause an error
924 nocrt: true,
925 }
926 `)
927
928 // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK-Ext
929 // library.
930 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
931 cc_library {
932 name: "libvndk",
933 vendor_available: true,
934 vndk: {
935 enabled: true,
936 },
937 nocrt: true,
938 }
939
940 cc_library {
941 name: "libvndk_ext",
942 vendor: true,
943 vndk: {
944 enabled: true,
945 extends: "libvndk",
946 },
947 nocrt: true,
948 }
949
950 cc_library {
951 name: "libvndk_sp",
952 vendor_available: true,
953 vndk: {
954 enabled: true,
955 support_system_process: true,
956 },
957 nocrt: true,
958 }
959
960 cc_library {
961 name: "libvndk_sp_ext",
962 vendor: true,
963 vndk: {
964 enabled: true,
965 extends: "libvndk_sp",
966 support_system_process: true,
967 },
968 shared_libs: ["libvndk_ext"], // Cause an error
969 nocrt: true,
970 }
971 `)
972}
973
974func TestVndkUseVndkExtError(t *testing.T) {
975 // This test ensures an error is emitted if a VNDK/VNDK-SP library depends on a
976 // VNDK-Ext/VNDK-SP-Ext library.
Logan Chienf3511742017-10-31 18:04:35 +0800977 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
978 cc_library {
979 name: "libvndk",
980 vendor_available: true,
981 vndk: {
982 enabled: true,
983 },
984 nocrt: true,
985 }
986
987 cc_library {
988 name: "libvndk_ext",
989 vendor: true,
990 vndk: {
991 enabled: true,
992 extends: "libvndk",
993 },
994 nocrt: true,
995 }
996
997 cc_library {
998 name: "libvndk2",
999 vendor_available: true,
1000 vndk: {
1001 enabled: true,
1002 },
1003 shared_libs: ["libvndk_ext"],
1004 nocrt: true,
1005 }
1006 `)
1007
Martin Stjernholmef449fe2018-11-06 16:12:13 +00001008 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
Logan Chienf3511742017-10-31 18:04:35 +08001009 cc_library {
1010 name: "libvndk",
1011 vendor_available: true,
1012 vndk: {
1013 enabled: true,
1014 },
1015 nocrt: true,
1016 }
1017
1018 cc_library {
1019 name: "libvndk_ext",
1020 vendor: true,
1021 vndk: {
1022 enabled: true,
1023 extends: "libvndk",
1024 },
1025 nocrt: true,
1026 }
1027
1028 cc_library {
1029 name: "libvndk2",
1030 vendor_available: true,
1031 vndk: {
1032 enabled: true,
1033 },
1034 target: {
1035 vendor: {
1036 shared_libs: ["libvndk_ext"],
1037 },
1038 },
1039 nocrt: true,
1040 }
1041 `)
1042
1043 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
1044 cc_library {
1045 name: "libvndk_sp",
1046 vendor_available: true,
1047 vndk: {
1048 enabled: true,
1049 support_system_process: true,
1050 },
1051 nocrt: true,
1052 }
1053
1054 cc_library {
1055 name: "libvndk_sp_ext",
1056 vendor: true,
1057 vndk: {
1058 enabled: true,
1059 extends: "libvndk_sp",
1060 support_system_process: true,
1061 },
1062 nocrt: true,
1063 }
1064
1065 cc_library {
1066 name: "libvndk_sp_2",
1067 vendor_available: true,
1068 vndk: {
1069 enabled: true,
1070 support_system_process: true,
1071 },
1072 shared_libs: ["libvndk_sp_ext"],
1073 nocrt: true,
1074 }
1075 `)
1076
Martin Stjernholmef449fe2018-11-06 16:12:13 +00001077 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
Logan Chienf3511742017-10-31 18:04:35 +08001078 cc_library {
1079 name: "libvndk_sp",
1080 vendor_available: true,
1081 vndk: {
1082 enabled: true,
1083 },
1084 nocrt: true,
1085 }
1086
1087 cc_library {
1088 name: "libvndk_sp_ext",
1089 vendor: true,
1090 vndk: {
1091 enabled: true,
1092 extends: "libvndk_sp",
1093 },
1094 nocrt: true,
1095 }
1096
1097 cc_library {
1098 name: "libvndk_sp2",
1099 vendor_available: true,
1100 vndk: {
1101 enabled: true,
1102 },
1103 target: {
1104 vendor: {
1105 shared_libs: ["libvndk_sp_ext"],
1106 },
1107 },
1108 nocrt: true,
1109 }
1110 `)
1111}
1112
Colin Cross0af4b842015-04-30 16:36:18 -07001113var (
1114 str11 = "01234567891"
1115 str10 = str11[:10]
1116 str9 = str11[:9]
1117 str5 = str11[:5]
1118 str4 = str11[:4]
1119)
1120
1121var splitListForSizeTestCases = []struct {
1122 in []string
1123 out [][]string
1124 size int
1125}{
1126 {
1127 in: []string{str10},
1128 out: [][]string{{str10}},
1129 size: 10,
1130 },
1131 {
1132 in: []string{str9},
1133 out: [][]string{{str9}},
1134 size: 10,
1135 },
1136 {
1137 in: []string{str5},
1138 out: [][]string{{str5}},
1139 size: 10,
1140 },
1141 {
1142 in: []string{str11},
1143 out: nil,
1144 size: 10,
1145 },
1146 {
1147 in: []string{str10, str10},
1148 out: [][]string{{str10}, {str10}},
1149 size: 10,
1150 },
1151 {
1152 in: []string{str9, str10},
1153 out: [][]string{{str9}, {str10}},
1154 size: 10,
1155 },
1156 {
1157 in: []string{str10, str9},
1158 out: [][]string{{str10}, {str9}},
1159 size: 10,
1160 },
1161 {
1162 in: []string{str5, str4},
1163 out: [][]string{{str5, str4}},
1164 size: 10,
1165 },
1166 {
1167 in: []string{str5, str4, str5},
1168 out: [][]string{{str5, str4}, {str5}},
1169 size: 10,
1170 },
1171 {
1172 in: []string{str5, str4, str5, str4},
1173 out: [][]string{{str5, str4}, {str5, str4}},
1174 size: 10,
1175 },
1176 {
1177 in: []string{str5, str4, str5, str5},
1178 out: [][]string{{str5, str4}, {str5}, {str5}},
1179 size: 10,
1180 },
1181 {
1182 in: []string{str5, str5, str5, str4},
1183 out: [][]string{{str5}, {str5}, {str5, str4}},
1184 size: 10,
1185 },
1186 {
1187 in: []string{str9, str11},
1188 out: nil,
1189 size: 10,
1190 },
1191 {
1192 in: []string{str11, str9},
1193 out: nil,
1194 size: 10,
1195 },
1196}
1197
1198func TestSplitListForSize(t *testing.T) {
1199 for _, testCase := range splitListForSizeTestCases {
Colin Cross5b529592017-05-09 13:34:34 -07001200 out, _ := splitListForSize(android.PathsForTesting(testCase.in), testCase.size)
1201
1202 var outStrings [][]string
1203
1204 if len(out) > 0 {
1205 outStrings = make([][]string, len(out))
1206 for i, o := range out {
1207 outStrings[i] = o.Strings()
1208 }
1209 }
1210
1211 if !reflect.DeepEqual(outStrings, testCase.out) {
Colin Cross0af4b842015-04-30 16:36:18 -07001212 t.Errorf("incorrect output:")
1213 t.Errorf(" input: %#v", testCase.in)
1214 t.Errorf(" size: %d", testCase.size)
1215 t.Errorf(" expected: %#v", testCase.out)
Colin Cross5b529592017-05-09 13:34:34 -07001216 t.Errorf(" got: %#v", outStrings)
Colin Cross0af4b842015-04-30 16:36:18 -07001217 }
1218 }
1219}
Jeff Gaston294356f2017-09-27 17:05:30 -07001220
1221var staticLinkDepOrderTestCases = []struct {
1222 // This is a string representation of a map[moduleName][]moduleDependency .
1223 // It models the dependencies declared in an Android.bp file.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001224 inStatic string
1225
1226 // This is a string representation of a map[moduleName][]moduleDependency .
1227 // It models the dependencies declared in an Android.bp file.
1228 inShared string
Jeff Gaston294356f2017-09-27 17:05:30 -07001229
1230 // allOrdered is a string representation of a map[moduleName][]moduleDependency .
1231 // The keys of allOrdered specify which modules we would like to check.
1232 // The values of allOrdered specify the expected result (of the transitive closure of all
1233 // dependencies) for each module to test
1234 allOrdered string
1235
1236 // outOrdered is a string representation of a map[moduleName][]moduleDependency .
1237 // The keys of outOrdered specify which modules we would like to check.
1238 // The values of outOrdered specify the expected result (of the ordered linker command line)
1239 // for each module to test.
1240 outOrdered string
1241}{
1242 // Simple tests
1243 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001244 inStatic: "",
Jeff Gaston294356f2017-09-27 17:05:30 -07001245 outOrdered: "",
1246 },
1247 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001248 inStatic: "a:",
Jeff Gaston294356f2017-09-27 17:05:30 -07001249 outOrdered: "a:",
1250 },
1251 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001252 inStatic: "a:b; b:",
Jeff Gaston294356f2017-09-27 17:05:30 -07001253 outOrdered: "a:b; b:",
1254 },
1255 // Tests of reordering
1256 {
1257 // diamond example
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001258 inStatic: "a:d,b,c; b:d; c:d; d:",
Jeff Gaston294356f2017-09-27 17:05:30 -07001259 outOrdered: "a:b,c,d; b:d; c:d; d:",
1260 },
1261 {
1262 // somewhat real example
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001263 inStatic: "bsdiff_unittest:b,c,d,e,f,g,h,i; e:b",
Jeff Gaston294356f2017-09-27 17:05:30 -07001264 outOrdered: "bsdiff_unittest:c,d,e,b,f,g,h,i; e:b",
1265 },
1266 {
1267 // multiple reorderings
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001268 inStatic: "a:b,c,d,e; d:b; e:c",
Jeff Gaston294356f2017-09-27 17:05:30 -07001269 outOrdered: "a:d,b,e,c; d:b; e:c",
1270 },
1271 {
1272 // should reorder without adding new transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001273 inStatic: "bin:lib2,lib1; lib1:lib2,liboptional",
Jeff Gaston294356f2017-09-27 17:05:30 -07001274 allOrdered: "bin:lib1,lib2,liboptional; lib1:lib2,liboptional",
1275 outOrdered: "bin:lib1,lib2; lib1:lib2,liboptional",
1276 },
1277 {
1278 // multiple levels of dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001279 inStatic: "a:b,c,d,e,f,g,h; f:b,c,d; b:c,d; c:d",
Jeff Gaston294356f2017-09-27 17:05:30 -07001280 allOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d",
1281 outOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d",
1282 },
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001283 // shared dependencies
1284 {
1285 // Note that this test doesn't recurse, to minimize the amount of logic it tests.
1286 // So, we don't actually have to check that a shared dependency of c will change the order
1287 // of a library that depends statically on b and on c. We only need to check that if c has
1288 // a shared dependency on b, that that shows up in allOrdered.
1289 inShared: "c:b",
1290 allOrdered: "c:b",
1291 outOrdered: "c:",
1292 },
1293 {
1294 // This test doesn't actually include any shared dependencies but it's a reminder of what
1295 // the second phase of the above test would look like
1296 inStatic: "a:b,c; c:b",
1297 allOrdered: "a:c,b; c:b",
1298 outOrdered: "a:c,b; c:b",
1299 },
Jeff Gaston294356f2017-09-27 17:05:30 -07001300 // tiebreakers for when two modules specifying different orderings and there is no dependency
1301 // to dictate an order
1302 {
1303 // if the tie is between two modules at the end of a's deps, then a's order wins
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001304 inStatic: "a1:b,c,d,e; a2:b,c,e,d; b:d,e; c:e,d",
Jeff Gaston294356f2017-09-27 17:05:30 -07001305 outOrdered: "a1:b,c,d,e; a2:b,c,e,d; b:d,e; c:e,d",
1306 },
1307 {
1308 // if the tie is between two modules at the start of a's deps, then c's order is used
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001309 inStatic: "a1:d,e,b1,c1; b1:d,e; c1:e,d; a2:d,e,b2,c2; b2:d,e; c2:d,e",
Jeff Gaston294356f2017-09-27 17:05:30 -07001310 outOrdered: "a1:b1,c1,e,d; b1:d,e; c1:e,d; a2:b2,c2,d,e; b2:d,e; c2:d,e",
1311 },
1312 // Tests involving duplicate dependencies
1313 {
1314 // simple duplicate
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001315 inStatic: "a:b,c,c,b",
Jeff Gaston294356f2017-09-27 17:05:30 -07001316 outOrdered: "a:c,b",
1317 },
1318 {
1319 // duplicates with reordering
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001320 inStatic: "a:b,c,d,c; c:b",
Jeff Gaston294356f2017-09-27 17:05:30 -07001321 outOrdered: "a:d,c,b",
1322 },
1323 // Tests to confirm the nonexistence of infinite loops.
1324 // These cases should never happen, so as long as the test terminates and the
1325 // result is deterministic then that should be fine.
1326 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001327 inStatic: "a:a",
Jeff Gaston294356f2017-09-27 17:05:30 -07001328 outOrdered: "a:a",
1329 },
1330 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001331 inStatic: "a:b; b:c; c:a",
Jeff Gaston294356f2017-09-27 17:05:30 -07001332 allOrdered: "a:b,c; b:c,a; c:a,b",
1333 outOrdered: "a:b; b:c; c:a",
1334 },
1335 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001336 inStatic: "a:b,c; b:c,a; c:a,b",
Jeff Gaston294356f2017-09-27 17:05:30 -07001337 allOrdered: "a:c,a,b; b:a,b,c; c:b,c,a",
1338 outOrdered: "a:c,b; b:a,c; c:b,a",
1339 },
1340}
1341
1342// converts from a string like "a:b,c; d:e" to (["a","b"], {"a":["b","c"], "d":["e"]}, [{"a", "a.o"}, {"b", "b.o"}])
1343func parseModuleDeps(text string) (modulesInOrder []android.Path, allDeps map[android.Path][]android.Path) {
1344 // convert from "a:b,c; d:e" to "a:b,c;d:e"
1345 strippedText := strings.Replace(text, " ", "", -1)
1346 if len(strippedText) < 1 {
1347 return []android.Path{}, make(map[android.Path][]android.Path, 0)
1348 }
1349 allDeps = make(map[android.Path][]android.Path, 0)
1350
1351 // convert from "a:b,c;d:e" to ["a:b,c", "d:e"]
1352 moduleTexts := strings.Split(strippedText, ";")
1353
1354 outputForModuleName := func(moduleName string) android.Path {
1355 return android.PathForTesting(moduleName)
1356 }
1357
1358 for _, moduleText := range moduleTexts {
1359 // convert from "a:b,c" to ["a", "b,c"]
1360 components := strings.Split(moduleText, ":")
1361 if len(components) != 2 {
1362 panic(fmt.Sprintf("illegal module dep string %q from larger string %q; must contain one ':', not %v", moduleText, text, len(components)-1))
1363 }
1364 moduleName := components[0]
1365 moduleOutput := outputForModuleName(moduleName)
1366 modulesInOrder = append(modulesInOrder, moduleOutput)
1367
1368 depString := components[1]
1369 // convert from "b,c" to ["b", "c"]
1370 depNames := strings.Split(depString, ",")
1371 if len(depString) < 1 {
1372 depNames = []string{}
1373 }
1374 var deps []android.Path
1375 for _, depName := range depNames {
1376 deps = append(deps, outputForModuleName(depName))
1377 }
1378 allDeps[moduleOutput] = deps
1379 }
1380 return modulesInOrder, allDeps
1381}
1382
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001383func TestLinkReordering(t *testing.T) {
Jeff Gaston294356f2017-09-27 17:05:30 -07001384 for _, testCase := range staticLinkDepOrderTestCases {
1385 errs := []string{}
1386
1387 // parse testcase
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001388 _, givenTransitiveDeps := parseModuleDeps(testCase.inStatic)
Jeff Gaston294356f2017-09-27 17:05:30 -07001389 expectedModuleNames, expectedTransitiveDeps := parseModuleDeps(testCase.outOrdered)
1390 if testCase.allOrdered == "" {
1391 // allow the test case to skip specifying allOrdered
1392 testCase.allOrdered = testCase.outOrdered
1393 }
1394 _, expectedAllDeps := parseModuleDeps(testCase.allOrdered)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001395 _, givenAllSharedDeps := parseModuleDeps(testCase.inShared)
Jeff Gaston294356f2017-09-27 17:05:30 -07001396
1397 // For each module whose post-reordered dependencies were specified, validate that
1398 // reordering the inputs produces the expected outputs.
1399 for _, moduleName := range expectedModuleNames {
1400 moduleDeps := givenTransitiveDeps[moduleName]
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001401 givenSharedDeps := givenAllSharedDeps[moduleName]
1402 orderedAllDeps, orderedDeclaredDeps := orderDeps(moduleDeps, givenSharedDeps, givenTransitiveDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001403
1404 correctAllOrdered := expectedAllDeps[moduleName]
1405 if !reflect.DeepEqual(orderedAllDeps, correctAllOrdered) {
1406 errs = append(errs, fmt.Sprintf("orderDeps returned incorrect orderedAllDeps."+
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001407 "\nin static:%q"+
1408 "\nin shared:%q"+
Jeff Gaston294356f2017-09-27 17:05:30 -07001409 "\nmodule: %v"+
1410 "\nexpected: %s"+
1411 "\nactual: %s",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001412 testCase.inStatic, testCase.inShared, moduleName, correctAllOrdered, orderedAllDeps))
Jeff Gaston294356f2017-09-27 17:05:30 -07001413 }
1414
1415 correctOutputDeps := expectedTransitiveDeps[moduleName]
1416 if !reflect.DeepEqual(correctOutputDeps, orderedDeclaredDeps) {
1417 errs = append(errs, fmt.Sprintf("orderDeps returned incorrect orderedDeclaredDeps."+
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001418 "\nin static:%q"+
1419 "\nin shared:%q"+
Jeff Gaston294356f2017-09-27 17:05:30 -07001420 "\nmodule: %v"+
1421 "\nexpected: %s"+
1422 "\nactual: %s",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001423 testCase.inStatic, testCase.inShared, moduleName, correctOutputDeps, orderedDeclaredDeps))
Jeff Gaston294356f2017-09-27 17:05:30 -07001424 }
1425 }
1426
1427 if len(errs) > 0 {
1428 sort.Strings(errs)
1429 for _, err := range errs {
1430 t.Error(err)
1431 }
1432 }
1433 }
1434}
Logan Chienf3511742017-10-31 18:04:35 +08001435
Jeff Gaston294356f2017-09-27 17:05:30 -07001436func getOutputPaths(ctx *android.TestContext, variant string, moduleNames []string) (paths android.Paths) {
1437 for _, moduleName := range moduleNames {
1438 module := ctx.ModuleForTests(moduleName, variant).Module().(*Module)
1439 output := module.outputFile.Path()
1440 paths = append(paths, output)
1441 }
1442 return paths
1443}
1444
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001445func TestStaticLibDepReordering(t *testing.T) {
Jeff Gaston294356f2017-09-27 17:05:30 -07001446 ctx := testCc(t, `
1447 cc_library {
1448 name: "a",
1449 static_libs: ["b", "c", "d"],
Jiyong Park374510b2018-03-19 18:23:01 +09001450 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07001451 }
1452 cc_library {
1453 name: "b",
Jiyong Park374510b2018-03-19 18:23:01 +09001454 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07001455 }
1456 cc_library {
1457 name: "c",
1458 static_libs: ["b"],
Jiyong Park374510b2018-03-19 18:23:01 +09001459 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07001460 }
1461 cc_library {
1462 name: "d",
Jiyong Park374510b2018-03-19 18:23:01 +09001463 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07001464 }
1465
1466 `)
1467
1468 variant := "android_arm64_armv8-a_core_static"
1469 moduleA := ctx.ModuleForTests("a", variant).Module().(*Module)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001470 actual := moduleA.depsInLinkOrder
Jeff Gaston294356f2017-09-27 17:05:30 -07001471 expected := getOutputPaths(ctx, variant, []string{"c", "b", "d"})
1472
1473 if !reflect.DeepEqual(actual, expected) {
1474 t.Errorf("staticDeps orderings were not propagated correctly"+
1475 "\nactual: %v"+
1476 "\nexpected: %v",
1477 actual,
1478 expected,
1479 )
1480 }
Jiyong Parkd08b6972017-09-26 10:50:54 +09001481}
Jeff Gaston294356f2017-09-27 17:05:30 -07001482
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001483func TestStaticLibDepReorderingWithShared(t *testing.T) {
1484 ctx := testCc(t, `
1485 cc_library {
1486 name: "a",
1487 static_libs: ["b", "c"],
Jiyong Park374510b2018-03-19 18:23:01 +09001488 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001489 }
1490 cc_library {
1491 name: "b",
Jiyong Park374510b2018-03-19 18:23:01 +09001492 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001493 }
1494 cc_library {
1495 name: "c",
1496 shared_libs: ["b"],
Jiyong Park374510b2018-03-19 18:23:01 +09001497 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001498 }
1499
1500 `)
1501
1502 variant := "android_arm64_armv8-a_core_static"
1503 moduleA := ctx.ModuleForTests("a", variant).Module().(*Module)
1504 actual := moduleA.depsInLinkOrder
1505 expected := getOutputPaths(ctx, variant, []string{"c", "b"})
1506
1507 if !reflect.DeepEqual(actual, expected) {
1508 t.Errorf("staticDeps orderings did not account for shared libs"+
1509 "\nactual: %v"+
1510 "\nexpected: %v",
1511 actual,
1512 expected,
1513 )
1514 }
1515}
1516
Jiyong Parka46a4d52017-12-14 19:54:34 +09001517func TestLlndkHeaders(t *testing.T) {
1518 ctx := testCc(t, `
1519 llndk_headers {
1520 name: "libllndk_headers",
1521 export_include_dirs: ["my_include"],
1522 }
1523 llndk_library {
1524 name: "libllndk",
1525 export_llndk_headers: ["libllndk_headers"],
1526 }
1527 cc_library {
1528 name: "libvendor",
1529 shared_libs: ["libllndk"],
1530 vendor: true,
1531 srcs: ["foo.c"],
Logan Chienf3511742017-10-31 18:04:35 +08001532 no_libgcc: true,
1533 nocrt: true,
Jiyong Parka46a4d52017-12-14 19:54:34 +09001534 }
1535 `)
1536
1537 // _static variant is used since _shared reuses *.o from the static variant
1538 cc := ctx.ModuleForTests("libvendor", "android_arm_armv7-a-neon_vendor_static").Rule("cc")
1539 cflags := cc.Args["cFlags"]
1540 if !strings.Contains(cflags, "-Imy_include") {
1541 t.Errorf("cflags for libvendor must contain -Imy_include, but was %#v.", cflags)
1542 }
1543}
1544
Logan Chien43d34c32017-12-20 01:17:32 +08001545func checkRuntimeLibs(t *testing.T, expected []string, module *Module) {
1546 actual := module.Properties.AndroidMkRuntimeLibs
1547 if !reflect.DeepEqual(actual, expected) {
1548 t.Errorf("incorrect runtime_libs for shared libs"+
1549 "\nactual: %v"+
1550 "\nexpected: %v",
1551 actual,
1552 expected,
1553 )
1554 }
1555}
1556
1557const runtimeLibAndroidBp = `
1558 cc_library {
1559 name: "libvendor_available1",
1560 vendor_available: true,
1561 no_libgcc : true,
1562 nocrt : true,
1563 system_shared_libs : [],
1564 }
1565 cc_library {
1566 name: "libvendor_available2",
1567 vendor_available: true,
1568 runtime_libs: ["libvendor_available1"],
1569 no_libgcc : true,
1570 nocrt : true,
1571 system_shared_libs : [],
1572 }
1573 cc_library {
1574 name: "libvendor_available3",
1575 vendor_available: true,
1576 runtime_libs: ["libvendor_available1"],
1577 target: {
1578 vendor: {
1579 exclude_runtime_libs: ["libvendor_available1"],
1580 }
1581 },
1582 no_libgcc : true,
1583 nocrt : true,
1584 system_shared_libs : [],
1585 }
1586 cc_library {
1587 name: "libcore",
1588 runtime_libs: ["libvendor_available1"],
1589 no_libgcc : true,
1590 nocrt : true,
1591 system_shared_libs : [],
1592 }
1593 cc_library {
1594 name: "libvendor1",
1595 vendor: true,
1596 no_libgcc : true,
1597 nocrt : true,
1598 system_shared_libs : [],
1599 }
1600 cc_library {
1601 name: "libvendor2",
1602 vendor: true,
1603 runtime_libs: ["libvendor_available1", "libvendor1"],
1604 no_libgcc : true,
1605 nocrt : true,
1606 system_shared_libs : [],
1607 }
1608`
1609
1610func TestRuntimeLibs(t *testing.T) {
1611 ctx := testCc(t, runtimeLibAndroidBp)
1612
1613 // runtime_libs for core variants use the module names without suffixes.
1614 variant := "android_arm64_armv8-a_core_shared"
1615
1616 module := ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module)
1617 checkRuntimeLibs(t, []string{"libvendor_available1"}, module)
1618
1619 module = ctx.ModuleForTests("libcore", variant).Module().(*Module)
1620 checkRuntimeLibs(t, []string{"libvendor_available1"}, module)
1621
1622 // runtime_libs for vendor variants have '.vendor' suffixes if the modules have both core
1623 // and vendor variants.
1624 variant = "android_arm64_armv8-a_vendor_shared"
1625
1626 module = ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module)
1627 checkRuntimeLibs(t, []string{"libvendor_available1.vendor"}, module)
1628
1629 module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module)
1630 checkRuntimeLibs(t, []string{"libvendor_available1.vendor", "libvendor1"}, module)
1631}
1632
1633func TestExcludeRuntimeLibs(t *testing.T) {
1634 ctx := testCc(t, runtimeLibAndroidBp)
1635
1636 variant := "android_arm64_armv8-a_core_shared"
1637 module := ctx.ModuleForTests("libvendor_available3", variant).Module().(*Module)
1638 checkRuntimeLibs(t, []string{"libvendor_available1"}, module)
1639
1640 variant = "android_arm64_armv8-a_vendor_shared"
1641 module = ctx.ModuleForTests("libvendor_available3", variant).Module().(*Module)
1642 checkRuntimeLibs(t, nil, module)
1643}
1644
1645func TestRuntimeLibsNoVndk(t *testing.T) {
1646 ctx := testCcNoVndk(t, runtimeLibAndroidBp)
1647
1648 // If DeviceVndkVersion is not defined, then runtime_libs are copied as-is.
1649
1650 variant := "android_arm64_armv8-a_core_shared"
1651
1652 module := ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module)
1653 checkRuntimeLibs(t, []string{"libvendor_available1"}, module)
1654
1655 module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module)
1656 checkRuntimeLibs(t, []string{"libvendor_available1", "libvendor1"}, module)
1657}
1658
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00001659func checkStaticLibs(t *testing.T, expected []string, module *Module) {
1660 actual := module.Properties.AndroidMkStaticLibs
1661 if !reflect.DeepEqual(actual, expected) {
1662 t.Errorf("incorrect static_libs"+
1663 "\nactual: %v"+
1664 "\nexpected: %v",
1665 actual,
1666 expected,
1667 )
1668 }
1669}
1670
1671const staticLibAndroidBp = `
1672 cc_library {
1673 name: "lib1",
1674 }
1675 cc_library {
1676 name: "lib2",
1677 static_libs: ["lib1"],
1678 }
1679`
1680
1681func TestStaticLibDepExport(t *testing.T) {
1682 ctx := testCc(t, staticLibAndroidBp)
1683
1684 // Check the shared version of lib2.
1685 variant := "android_arm64_armv8-a_core_shared"
1686 module := ctx.ModuleForTests("lib2", variant).Module().(*Module)
1687 checkStaticLibs(t, []string{"lib1", "libclang_rt.builtins-aarch64-android", "libatomic", "libgcc"}, module)
1688
1689 // Check the static version of lib2.
1690 variant = "android_arm64_armv8-a_core_static"
1691 module = ctx.ModuleForTests("lib2", variant).Module().(*Module)
1692 // libc++_static is linked additionally.
1693 checkStaticLibs(t, []string{"lib1", "libc++_static", "libclang_rt.builtins-aarch64-android", "libatomic", "libgcc"}, module)
1694}
1695
Jiyong Parkd08b6972017-09-26 10:50:54 +09001696var compilerFlagsTestCases = []struct {
1697 in string
1698 out bool
1699}{
1700 {
1701 in: "a",
1702 out: false,
1703 },
1704 {
1705 in: "-a",
1706 out: true,
1707 },
1708 {
1709 in: "-Ipath/to/something",
1710 out: false,
1711 },
1712 {
1713 in: "-isystempath/to/something",
1714 out: false,
1715 },
1716 {
1717 in: "--coverage",
1718 out: false,
1719 },
1720 {
1721 in: "-include a/b",
1722 out: true,
1723 },
1724 {
1725 in: "-include a/b c/d",
1726 out: false,
1727 },
1728 {
1729 in: "-DMACRO",
1730 out: true,
1731 },
1732 {
1733 in: "-DMAC RO",
1734 out: false,
1735 },
1736 {
1737 in: "-a -b",
1738 out: false,
1739 },
1740 {
1741 in: "-DMACRO=definition",
1742 out: true,
1743 },
1744 {
1745 in: "-DMACRO=defi nition",
1746 out: true, // TODO(jiyong): this should be false
1747 },
1748 {
1749 in: "-DMACRO(x)=x + 1",
1750 out: true,
1751 },
1752 {
1753 in: "-DMACRO=\"defi nition\"",
1754 out: true,
1755 },
1756}
1757
1758type mockContext struct {
1759 BaseModuleContext
1760 result bool
1761}
1762
1763func (ctx *mockContext) PropertyErrorf(property, format string, args ...interface{}) {
1764 // CheckBadCompilerFlags calls this function when the flag should be rejected
1765 ctx.result = false
1766}
1767
1768func TestCompilerFlags(t *testing.T) {
1769 for _, testCase := range compilerFlagsTestCases {
1770 ctx := &mockContext{result: true}
1771 CheckBadCompilerFlags(ctx, "", []string{testCase.in})
1772 if ctx.result != testCase.out {
1773 t.Errorf("incorrect output:")
1774 t.Errorf(" input: %#v", testCase.in)
1775 t.Errorf(" expected: %#v", testCase.out)
1776 t.Errorf(" got: %#v", ctx.result)
1777 }
1778 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001779}
Jiyong Park374510b2018-03-19 18:23:01 +09001780
1781func TestVendorPublicLibraries(t *testing.T) {
1782 ctx := testCc(t, `
1783 cc_library_headers {
1784 name: "libvendorpublic_headers",
1785 export_include_dirs: ["my_include"],
1786 }
1787 vendor_public_library {
1788 name: "libvendorpublic",
1789 symbol_file: "",
1790 export_public_headers: ["libvendorpublic_headers"],
1791 }
1792 cc_library {
1793 name: "libvendorpublic",
1794 srcs: ["foo.c"],
1795 vendor: true,
1796 no_libgcc: true,
1797 nocrt: true,
1798 }
1799
1800 cc_library {
1801 name: "libsystem",
1802 shared_libs: ["libvendorpublic"],
1803 vendor: false,
1804 srcs: ["foo.c"],
1805 no_libgcc: true,
1806 nocrt: true,
1807 }
1808 cc_library {
1809 name: "libvendor",
1810 shared_libs: ["libvendorpublic"],
1811 vendor: true,
1812 srcs: ["foo.c"],
1813 no_libgcc: true,
1814 nocrt: true,
1815 }
1816 `)
1817
1818 variant := "android_arm64_armv8-a_core_shared"
1819
1820 // test if header search paths are correctly added
1821 // _static variant is used since _shared reuses *.o from the static variant
1822 cc := ctx.ModuleForTests("libsystem", strings.Replace(variant, "_shared", "_static", 1)).Rule("cc")
1823 cflags := cc.Args["cFlags"]
1824 if !strings.Contains(cflags, "-Imy_include") {
1825 t.Errorf("cflags for libsystem must contain -Imy_include, but was %#v.", cflags)
1826 }
1827
1828 // test if libsystem is linked to the stub
1829 ld := ctx.ModuleForTests("libsystem", variant).Rule("ld")
1830 libflags := ld.Args["libFlags"]
1831 stubPaths := getOutputPaths(ctx, variant, []string{"libvendorpublic" + vendorPublicLibrarySuffix})
1832 if !strings.Contains(libflags, stubPaths[0].String()) {
1833 t.Errorf("libflags for libsystem must contain %#v, but was %#v", stubPaths[0], libflags)
1834 }
1835
1836 // test if libvendor is linked to the real shared lib
1837 ld = ctx.ModuleForTests("libvendor", strings.Replace(variant, "_core", "_vendor", 1)).Rule("ld")
1838 libflags = ld.Args["libFlags"]
1839 stubPaths = getOutputPaths(ctx, strings.Replace(variant, "_core", "_vendor", 1), []string{"libvendorpublic"})
1840 if !strings.Contains(libflags, stubPaths[0].String()) {
1841 t.Errorf("libflags for libvendor must contain %#v, but was %#v", stubPaths[0], libflags)
1842 }
1843
1844}
Jiyong Park37b25202018-07-11 10:49:27 +09001845
1846func TestRecovery(t *testing.T) {
1847 ctx := testCc(t, `
1848 cc_library_shared {
1849 name: "librecovery",
1850 recovery: true,
1851 }
1852 cc_library_shared {
1853 name: "librecovery32",
1854 recovery: true,
1855 compile_multilib:"32",
1856 }
Jiyong Park5baac542018-08-28 09:55:37 +09001857 cc_library_shared {
1858 name: "libHalInRecovery",
1859 recovery_available: true,
1860 vendor: true,
1861 }
Jiyong Park37b25202018-07-11 10:49:27 +09001862 `)
1863
1864 variants := ctx.ModuleVariantsForTests("librecovery")
1865 const arm64 = "android_arm64_armv8-a_recovery_shared"
1866 if len(variants) != 1 || !android.InList(arm64, variants) {
1867 t.Errorf("variants of librecovery must be \"%s\" only, but was %#v", arm64, variants)
1868 }
1869
1870 variants = ctx.ModuleVariantsForTests("librecovery32")
1871 if android.InList(arm64, variants) {
1872 t.Errorf("multilib was set to 32 for librecovery32, but its variants has %s.", arm64)
1873 }
Jiyong Park5baac542018-08-28 09:55:37 +09001874
1875 recoveryModule := ctx.ModuleForTests("libHalInRecovery", recoveryVariant).Module().(*Module)
1876 if !recoveryModule.Platform() {
1877 t.Errorf("recovery variant of libHalInRecovery must not specific to device, soc, or product")
1878 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09001879}
Jiyong Park5baac542018-08-28 09:55:37 +09001880
Jiyong Park7ed9de32018-10-15 22:25:07 +09001881func TestVersionedStubs(t *testing.T) {
1882 ctx := testCc(t, `
1883 cc_library_shared {
1884 name: "libFoo",
Jiyong Parkda732bd2018-11-02 18:23:15 +09001885 srcs: ["foo.c"],
Jiyong Park7ed9de32018-10-15 22:25:07 +09001886 stubs: {
1887 symbol_file: "foo.map.txt",
1888 versions: ["1", "2", "3"],
1889 },
1890 }
Jiyong Parkda732bd2018-11-02 18:23:15 +09001891
Jiyong Park7ed9de32018-10-15 22:25:07 +09001892 cc_library_shared {
1893 name: "libBar",
Jiyong Parkda732bd2018-11-02 18:23:15 +09001894 srcs: ["bar.c"],
Jiyong Park7ed9de32018-10-15 22:25:07 +09001895 shared_libs: ["libFoo#1"],
1896 }`)
1897
1898 variants := ctx.ModuleVariantsForTests("libFoo")
1899 expectedVariants := []string{
1900 "android_arm64_armv8-a_core_shared",
1901 "android_arm64_armv8-a_core_shared_1",
1902 "android_arm64_armv8-a_core_shared_2",
1903 "android_arm64_armv8-a_core_shared_3",
1904 "android_arm_armv7-a-neon_core_shared",
1905 "android_arm_armv7-a-neon_core_shared_1",
1906 "android_arm_armv7-a-neon_core_shared_2",
1907 "android_arm_armv7-a-neon_core_shared_3",
1908 }
1909 variantsMismatch := false
1910 if len(variants) != len(expectedVariants) {
1911 variantsMismatch = true
1912 } else {
1913 for _, v := range expectedVariants {
1914 if !inList(v, variants) {
1915 variantsMismatch = false
1916 }
1917 }
1918 }
1919 if variantsMismatch {
1920 t.Errorf("variants of libFoo expected:\n")
1921 for _, v := range expectedVariants {
1922 t.Errorf("%q\n", v)
1923 }
1924 t.Errorf(", but got:\n")
1925 for _, v := range variants {
1926 t.Errorf("%q\n", v)
1927 }
1928 }
1929
1930 libBarLinkRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_core_shared").Rule("ld")
1931 libFlags := libBarLinkRule.Args["libFlags"]
1932 libFoo1StubPath := "libFoo/android_arm64_armv8-a_core_shared_1/libFoo.so"
1933 if !strings.Contains(libFlags, libFoo1StubPath) {
1934 t.Errorf("%q is not found in %q", libFoo1StubPath, libFlags)
1935 }
Jiyong Parkda732bd2018-11-02 18:23:15 +09001936
1937 libBarCompileRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_core_shared").Rule("cc")
1938 cFlags := libBarCompileRule.Args["cFlags"]
1939 libFoo1VersioningMacro := "-D__LIBFOO_API__=1"
1940 if !strings.Contains(cFlags, libFoo1VersioningMacro) {
1941 t.Errorf("%q is not found in %q", libFoo1VersioningMacro, cFlags)
1942 }
Jiyong Park37b25202018-07-11 10:49:27 +09001943}
Jaewoong Jung232c07c2018-12-18 11:08:25 -08001944
1945func TestStaticExecutable(t *testing.T) {
1946 ctx := testCc(t, `
1947 cc_binary {
1948 name: "static_test",
1949 srcs: ["foo.c"],
1950 static_executable: true,
1951 }`)
1952
1953 variant := "android_arm64_armv8-a_core"
1954 binModuleRule := ctx.ModuleForTests("static_test", variant).Rule("ld")
1955 libFlags := binModuleRule.Args["libFlags"]
1956 systemStaticLibs := []string{"libc.a", "libm.a", "libdl.a"}
1957 for _, lib := range systemStaticLibs {
1958 if !strings.Contains(libFlags, lib) {
1959 t.Errorf("Static lib %q was not found in %q", lib, libFlags)
1960 }
1961 }
1962 systemSharedLibs := []string{"libc.so", "libm.so", "libdl.so"}
1963 for _, lib := range systemSharedLibs {
1964 if strings.Contains(libFlags, lib) {
1965 t.Errorf("Shared lib %q was found in %q", lib, libFlags)
1966 }
1967 }
1968}