blob: 96233a10e7f6a8346b2c4e765d824c27ad56822b [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
Logan Chienf3511742017-10-31 18:04:35 +080054func createTestContext(t *testing.T, config android.Config, bp string) *android.TestContext {
Jiyong Park6a43f042017-10-12 23:05:00 +090055 ctx := android.NewTestArchContext()
Jiyong Park16e91a02018-12-20 18:18:08 +090056 ctx.RegisterModuleType("cc_binary", android.ModuleFactoryAdaptor(BinaryFactory))
Steven Morelandf9e62162017-11-02 17:00:50 -070057 ctx.RegisterModuleType("cc_library", android.ModuleFactoryAdaptor(LibraryFactory))
Colin Crossf18e1102017-11-16 14:33:08 -080058 ctx.RegisterModuleType("cc_library_shared", android.ModuleFactoryAdaptor(LibrarySharedFactory))
Jiyong Park374510b2018-03-19 18:23:01 +090059 ctx.RegisterModuleType("cc_library_headers", android.ModuleFactoryAdaptor(LibraryHeaderFactory))
Colin Crosse40b4ea2018-10-02 22:25:58 -070060 ctx.RegisterModuleType("toolchain_library", android.ModuleFactoryAdaptor(ToolchainLibraryFactory))
Jiyong Parkda6eb592018-12-19 17:12:36 +090061 ctx.RegisterModuleType("llndk_library", android.ModuleFactoryAdaptor(LlndkLibraryFactory))
Jiyong Parka46a4d52017-12-14 19:54:34 +090062 ctx.RegisterModuleType("llndk_headers", android.ModuleFactoryAdaptor(llndkHeadersFactory))
Jiyong Park374510b2018-03-19 18:23:01 +090063 ctx.RegisterModuleType("vendor_public_library", android.ModuleFactoryAdaptor(vendorPublicLibraryFactory))
Colin Crosse40b4ea2018-10-02 22:25:58 -070064 ctx.RegisterModuleType("cc_object", android.ModuleFactoryAdaptor(ObjectFactory))
Pirama Arumuga Nainar955dc492018-04-17 14:58:42 -070065 ctx.RegisterModuleType("filegroup", android.ModuleFactoryAdaptor(android.FileGroupFactory))
Jiyong Park6a43f042017-10-12 23:05:00 +090066 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Jiyong Parkda6eb592018-12-19 17:12:36 +090067 ctx.BottomUp("image", ImageMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070068 ctx.BottomUp("link", LinkageMutator).Parallel()
Jiyong Parkda6eb592018-12-19 17:12:36 +090069 ctx.BottomUp("vndk", VndkMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +090070 ctx.BottomUp("version", VersionMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070071 ctx.BottomUp("begin", BeginMutator).Parallel()
Jiyong Park6a43f042017-10-12 23:05:00 +090072 })
73 ctx.Register()
74
Jeff Gaston294356f2017-09-27 17:05:30 -070075 // add some modules that are required by the compiler and/or linker
76 bp = bp + `
77 toolchain_library {
78 name: "libatomic",
79 vendor_available: true,
Jiyong Park37b25202018-07-11 10:49:27 +090080 recovery_available: true,
Dan Willemsenfeea4df2018-10-07 18:16:48 -070081 src: "",
Jeff Gaston294356f2017-09-27 17:05:30 -070082 }
83
84 toolchain_library {
85 name: "libcompiler_rt-extras",
86 vendor_available: true,
Jiyong Park37b25202018-07-11 10:49:27 +090087 recovery_available: true,
Dan Willemsenfeea4df2018-10-07 18:16:48 -070088 src: "",
Jeff Gaston294356f2017-09-27 17:05:30 -070089 }
90
91 toolchain_library {
Yi Kong7df0f302018-10-08 22:10:12 +000092 name: "libclang_rt.builtins-arm-android",
93 vendor_available: true,
94 recovery_available: true,
95 src: "",
96 }
97
98 toolchain_library {
99 name: "libclang_rt.builtins-aarch64-android",
100 vendor_available: true,
101 recovery_available: true,
102 src: "",
103 }
104
105 toolchain_library {
106 name: "libclang_rt.builtins-i686-android",
107 vendor_available: true,
108 recovery_available: true,
109 src: "",
110 }
111
112 toolchain_library {
113 name: "libclang_rt.builtins-x86_64-android",
114 vendor_available: true,
115 recovery_available: true,
116 src: "",
117 }
118
119 toolchain_library {
Jeff Gaston294356f2017-09-27 17:05:30 -0700120 name: "libgcc",
121 vendor_available: true,
Jiyong Park37b25202018-07-11 10:49:27 +0900122 recovery_available: true,
Dan Willemsenfeea4df2018-10-07 18:16:48 -0700123 src: "",
Jeff Gaston294356f2017-09-27 17:05:30 -0700124 }
125
126 cc_library {
127 name: "libc",
Logan Chienf3511742017-10-31 18:04:35 +0800128 no_libgcc: true,
129 nocrt: true,
Jeff Gaston294356f2017-09-27 17:05:30 -0700130 system_shared_libs: [],
Jiyong Park37b25202018-07-11 10:49:27 +0900131 recovery_available: true,
Jeff Gaston294356f2017-09-27 17:05:30 -0700132 }
133 llndk_library {
134 name: "libc",
135 symbol_file: "",
136 }
137 cc_library {
138 name: "libm",
Logan Chienf3511742017-10-31 18:04:35 +0800139 no_libgcc: true,
140 nocrt: true,
Jeff Gaston294356f2017-09-27 17:05:30 -0700141 system_shared_libs: [],
Jiyong Park37b25202018-07-11 10:49:27 +0900142 recovery_available: true,
Jeff Gaston294356f2017-09-27 17:05:30 -0700143 }
144 llndk_library {
145 name: "libm",
146 symbol_file: "",
147 }
148 cc_library {
149 name: "libdl",
Logan Chienf3511742017-10-31 18:04:35 +0800150 no_libgcc: true,
151 nocrt: true,
Jeff Gaston294356f2017-09-27 17:05:30 -0700152 system_shared_libs: [],
Jiyong Park37b25202018-07-11 10:49:27 +0900153 recovery_available: true,
Jeff Gaston294356f2017-09-27 17:05:30 -0700154 }
155 llndk_library {
156 name: "libdl",
157 symbol_file: "",
158 }
Jaewoong Jung3e6b1fb2018-11-02 22:56:30 +0000159 cc_library {
Jiyong Park374510b2018-03-19 18:23:01 +0900160 name: "libc++_static",
161 no_libgcc: true,
162 nocrt: true,
163 system_shared_libs: [],
164 stl: "none",
165 vendor_available: true,
Jiyong Park37b25202018-07-11 10:49:27 +0900166 recovery_available: true,
Jiyong Park374510b2018-03-19 18:23:01 +0900167 }
168 cc_library {
169 name: "libc++",
170 no_libgcc: true,
171 nocrt: true,
172 system_shared_libs: [],
173 stl: "none",
174 vendor_available: true,
Jiyong Park37b25202018-07-11 10:49:27 +0900175 recovery_available: true,
Jiyong Park374510b2018-03-19 18:23:01 +0900176 vndk: {
177 enabled: true,
178 support_system_process: true,
179 },
180 }
181 cc_library {
182 name: "libunwind_llvm",
183 no_libgcc: true,
184 nocrt: true,
185 system_shared_libs: [],
186 stl: "none",
187 vendor_available: true,
Jiyong Park37b25202018-07-11 10:49:27 +0900188 recovery_available: true,
Jiyong Park374510b2018-03-19 18:23:01 +0900189 }
Jeff Gaston294356f2017-09-27 17:05:30 -0700190
191 cc_object {
192 name: "crtbegin_so",
Jiyong Park37b25202018-07-11 10:49:27 +0900193 recovery_available: true,
Jiyong Park5baac542018-08-28 09:55:37 +0900194 vendor_available: true,
Jeff Gaston294356f2017-09-27 17:05:30 -0700195 }
196
197 cc_object {
Jaewoong Jung232c07c2018-12-18 11:08:25 -0800198 name: "crtbegin_static",
199 recovery_available: true,
200 vendor_available: true,
201 }
202
203 cc_object {
Jeff Gaston294356f2017-09-27 17:05:30 -0700204 name: "crtend_so",
Jiyong Park37b25202018-07-11 10:49:27 +0900205 recovery_available: true,
Jiyong Park5baac542018-08-28 09:55:37 +0900206 vendor_available: true,
Jeff Gaston294356f2017-09-27 17:05:30 -0700207 }
208
Jaewoong Jung232c07c2018-12-18 11:08:25 -0800209 cc_object {
210 name: "crtend_android",
211 recovery_available: true,
212 vendor_available: true,
213 }
214
Colin Crossad59e752017-11-16 14:29:11 -0800215 cc_library {
216 name: "libprotobuf-cpp-lite",
217 }
218
Jeff Gaston294356f2017-09-27 17:05:30 -0700219`
220
Jiyong Park6a43f042017-10-12 23:05:00 +0900221 ctx.MockFileSystem(map[string][]byte{
Jiyong Park7ed9de32018-10-15 22:25:07 +0900222 "Android.bp": []byte(bp),
223 "foo.c": nil,
224 "bar.c": nil,
225 "a.proto": nil,
226 "b.aidl": nil,
227 "my_include": nil,
228 "foo.map.txt": nil,
Jiyong Park6a43f042017-10-12 23:05:00 +0900229 })
230
Logan Chienf3511742017-10-31 18:04:35 +0800231 return ctx
232}
233
234func testCcWithConfig(t *testing.T, bp string, config android.Config) *android.TestContext {
Logan Chiend3c59a22018-03-29 14:08:15 +0800235 t.Helper()
Logan Chienf3511742017-10-31 18:04:35 +0800236 ctx := createTestContext(t, config, bp)
237
Jeff Gastond3e141d2017-08-08 17:46:01 -0700238 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
Logan Chien42039712018-03-12 16:29:17 +0800239 android.FailIfErrored(t, errs)
Jiyong Park6a43f042017-10-12 23:05:00 +0900240 _, errs = ctx.PrepareBuildActions(config)
Logan Chien42039712018-03-12 16:29:17 +0800241 android.FailIfErrored(t, errs)
Jiyong Park6a43f042017-10-12 23:05:00 +0900242
243 return ctx
244}
245
Logan Chienf3511742017-10-31 18:04:35 +0800246func testCc(t *testing.T, bp string) *android.TestContext {
Logan Chiend3c59a22018-03-29 14:08:15 +0800247 t.Helper()
Logan Chienf3511742017-10-31 18:04:35 +0800248 config := android.TestArchConfig(buildDir, nil)
Dan Willemsen674dc7f2018-03-12 18:06:05 -0700249 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
250 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
Logan Chienf3511742017-10-31 18:04:35 +0800251
252 return testCcWithConfig(t, bp, config)
253}
254
255func testCcNoVndk(t *testing.T, bp string) *android.TestContext {
Logan Chiend3c59a22018-03-29 14:08:15 +0800256 t.Helper()
Logan Chienf3511742017-10-31 18:04:35 +0800257 config := android.TestArchConfig(buildDir, nil)
Dan Willemsen674dc7f2018-03-12 18:06:05 -0700258 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
Logan Chienf3511742017-10-31 18:04:35 +0800259
260 return testCcWithConfig(t, bp, config)
261}
262
263func testCcError(t *testing.T, pattern string, bp string) {
Logan Chiend3c59a22018-03-29 14:08:15 +0800264 t.Helper()
Logan Chienf3511742017-10-31 18:04:35 +0800265 config := android.TestArchConfig(buildDir, nil)
Dan Willemsen674dc7f2018-03-12 18:06:05 -0700266 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
267 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
Logan Chienf3511742017-10-31 18:04:35 +0800268
269 ctx := createTestContext(t, config, bp)
270
271 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
272 if len(errs) > 0 {
Logan Chienee97c3e2018-03-12 16:34:26 +0800273 android.FailIfNoMatchingErrors(t, pattern, errs)
Logan Chienf3511742017-10-31 18:04:35 +0800274 return
275 }
276
277 _, errs = ctx.PrepareBuildActions(config)
278 if len(errs) > 0 {
Logan Chienee97c3e2018-03-12 16:34:26 +0800279 android.FailIfNoMatchingErrors(t, pattern, errs)
Logan Chienf3511742017-10-31 18:04:35 +0800280 return
281 }
282
283 t.Fatalf("missing expected error %q (0 errors are returned)", pattern)
284}
285
286const (
Jiyong Park5baac542018-08-28 09:55:37 +0900287 coreVariant = "android_arm64_armv8-a_core_shared"
288 vendorVariant = "android_arm64_armv8-a_vendor_shared"
289 recoveryVariant = "android_arm64_armv8-a_recovery_shared"
Logan Chienf3511742017-10-31 18:04:35 +0800290)
291
Jiyong Park6a43f042017-10-12 23:05:00 +0900292func TestVendorSrc(t *testing.T) {
293 ctx := testCc(t, `
294 cc_library {
295 name: "libTest",
296 srcs: ["foo.c"],
Logan Chienf3511742017-10-31 18:04:35 +0800297 no_libgcc: true,
298 nocrt: true,
299 system_shared_libs: [],
Jiyong Park6a43f042017-10-12 23:05:00 +0900300 vendor_available: true,
301 target: {
302 vendor: {
303 srcs: ["bar.c"],
304 },
305 },
306 }
Jiyong Park6a43f042017-10-12 23:05:00 +0900307 `)
308
Logan Chienf3511742017-10-31 18:04:35 +0800309 ld := ctx.ModuleForTests("libTest", vendorVariant).Rule("ld")
Jiyong Park6a43f042017-10-12 23:05:00 +0900310 var objs []string
311 for _, o := range ld.Inputs {
312 objs = append(objs, o.Base())
313 }
Colin Cross95d33fe2018-01-03 13:40:46 -0800314 if len(objs) != 2 || objs[0] != "foo.o" || objs[1] != "bar.o" {
Jiyong Park6a43f042017-10-12 23:05:00 +0900315 t.Errorf("inputs of libTest must be []string{\"foo.o\", \"bar.o\"}, but was %#v.", objs)
316 }
317}
318
Logan Chienf3511742017-10-31 18:04:35 +0800319func checkVndkModule(t *testing.T, ctx *android.TestContext, name, subDir string,
320 isVndkSp bool, extends string) {
321
Logan Chiend3c59a22018-03-29 14:08:15 +0800322 t.Helper()
323
Logan Chienf3511742017-10-31 18:04:35 +0800324 mod := ctx.ModuleForTests(name, vendorVariant).Module().(*Module)
325 if !mod.hasVendorVariant() {
Colin Crossf46e37f2018-03-21 16:25:58 -0700326 t.Errorf("%q must have vendor variant", name)
Logan Chienf3511742017-10-31 18:04:35 +0800327 }
328
329 // Check library properties.
330 lib, ok := mod.compiler.(*libraryDecorator)
331 if !ok {
332 t.Errorf("%q must have libraryDecorator", name)
333 } else if lib.baseInstaller.subDir != subDir {
334 t.Errorf("%q must use %q as subdir but it is using %q", name, subDir,
335 lib.baseInstaller.subDir)
336 }
337
338 // Check VNDK properties.
339 if mod.vndkdep == nil {
340 t.Fatalf("%q must have `vndkdep`", name)
341 }
342 if !mod.isVndk() {
343 t.Errorf("%q isVndk() must equal to true", name)
344 }
345 if mod.isVndkSp() != isVndkSp {
346 t.Errorf("%q isVndkSp() must equal to %t", name, isVndkSp)
347 }
348
349 // Check VNDK extension properties.
350 isVndkExt := extends != ""
351 if mod.isVndkExt() != isVndkExt {
352 t.Errorf("%q isVndkExt() must equal to %t", name, isVndkExt)
353 }
354
355 if actualExtends := mod.getVndkExtendsModuleName(); actualExtends != extends {
356 t.Errorf("%q must extend from %q but get %q", name, extends, actualExtends)
357 }
358}
359
360func TestVndk(t *testing.T) {
361 ctx := testCc(t, `
362 cc_library {
363 name: "libvndk",
364 vendor_available: true,
365 vndk: {
366 enabled: true,
367 },
368 nocrt: true,
369 }
370
371 cc_library {
372 name: "libvndk_private",
373 vendor_available: false,
374 vndk: {
375 enabled: true,
376 },
377 nocrt: true,
378 }
379
380 cc_library {
381 name: "libvndk_sp",
382 vendor_available: true,
383 vndk: {
384 enabled: true,
385 support_system_process: true,
386 },
387 nocrt: true,
388 }
389
390 cc_library {
391 name: "libvndk_sp_private",
392 vendor_available: false,
393 vndk: {
394 enabled: true,
395 support_system_process: true,
396 },
397 nocrt: true,
398 }
399 `)
400
401 checkVndkModule(t, ctx, "libvndk", "vndk-VER", false, "")
402 checkVndkModule(t, ctx, "libvndk_private", "vndk-VER", false, "")
403 checkVndkModule(t, ctx, "libvndk_sp", "vndk-sp-VER", true, "")
404 checkVndkModule(t, ctx, "libvndk_sp_private", "vndk-sp-VER", true, "")
405}
406
Logan Chiend3c59a22018-03-29 14:08:15 +0800407func TestVndkDepError(t *testing.T) {
408 // Check whether an error is emitted when a VNDK lib depends on a system lib.
409 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
410 cc_library {
411 name: "libvndk",
412 vendor_available: true,
413 vndk: {
414 enabled: true,
415 },
416 shared_libs: ["libfwk"], // Cause error
417 nocrt: true,
418 }
419
420 cc_library {
421 name: "libfwk",
422 nocrt: true,
423 }
424 `)
425
426 // Check whether an error is emitted when a VNDK lib depends on a vendor lib.
427 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
428 cc_library {
429 name: "libvndk",
430 vendor_available: true,
431 vndk: {
432 enabled: true,
433 },
434 shared_libs: ["libvendor"], // Cause error
435 nocrt: true,
436 }
437
438 cc_library {
439 name: "libvendor",
440 vendor: true,
441 nocrt: true,
442 }
443 `)
444
445 // Check whether an error is emitted when a VNDK-SP lib depends on a system lib.
446 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
447 cc_library {
448 name: "libvndk_sp",
449 vendor_available: true,
450 vndk: {
451 enabled: true,
452 support_system_process: true,
453 },
454 shared_libs: ["libfwk"], // Cause error
455 nocrt: true,
456 }
457
458 cc_library {
459 name: "libfwk",
460 nocrt: true,
461 }
462 `)
463
464 // Check whether an error is emitted when a VNDK-SP lib depends on a vendor lib.
465 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
466 cc_library {
467 name: "libvndk_sp",
468 vendor_available: true,
469 vndk: {
470 enabled: true,
471 support_system_process: true,
472 },
473 shared_libs: ["libvendor"], // Cause error
474 nocrt: true,
475 }
476
477 cc_library {
478 name: "libvendor",
479 vendor: true,
480 nocrt: true,
481 }
482 `)
483
484 // Check whether an error is emitted when a VNDK-SP lib depends on a VNDK lib.
485 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
486 cc_library {
487 name: "libvndk_sp",
488 vendor_available: true,
489 vndk: {
490 enabled: true,
491 support_system_process: true,
492 },
493 shared_libs: ["libvndk"], // Cause error
494 nocrt: true,
495 }
496
497 cc_library {
498 name: "libvndk",
499 vendor_available: true,
500 vndk: {
501 enabled: true,
502 },
503 nocrt: true,
504 }
505 `)
506}
507
Justin Yun9357f4a2018-11-28 15:14:47 +0900508func TestVndkMustNotBeProductSpecific(t *testing.T) {
509 // Check whether an error is emitted when a vndk lib has 'product_specific: true'.
510 testCcError(t, "product_specific must not be true when `vndk: {enabled: true}`", `
511 cc_library {
512 name: "libvndk",
513 product_specific: true, // Cause error
514 vendor_available: true,
515 vndk: {
516 enabled: true,
517 },
518 nocrt: true,
519 }
520 `)
521}
522
Logan Chienf3511742017-10-31 18:04:35 +0800523func TestVndkExt(t *testing.T) {
524 // This test checks the VNDK-Ext properties.
525 ctx := testCc(t, `
526 cc_library {
527 name: "libvndk",
528 vendor_available: true,
529 vndk: {
530 enabled: true,
531 },
532 nocrt: true,
533 }
534
535 cc_library {
536 name: "libvndk_ext",
537 vendor: true,
538 vndk: {
539 enabled: true,
540 extends: "libvndk",
541 },
542 nocrt: true,
543 }
544 `)
545
546 checkVndkModule(t, ctx, "libvndk_ext", "vndk", false, "libvndk")
547}
548
Logan Chiend3c59a22018-03-29 14:08:15 +0800549func TestVndkExtWithoutBoardVndkVersion(t *testing.T) {
Logan Chienf3511742017-10-31 18:04:35 +0800550 // This test checks the VNDK-Ext properties when BOARD_VNDK_VERSION is not set.
551 ctx := testCcNoVndk(t, `
552 cc_library {
553 name: "libvndk",
554 vendor_available: true,
555 vndk: {
556 enabled: true,
557 },
558 nocrt: true,
559 }
560
561 cc_library {
562 name: "libvndk_ext",
563 vendor: true,
564 vndk: {
565 enabled: true,
566 extends: "libvndk",
567 },
568 nocrt: true,
569 }
570 `)
571
572 // Ensures that the core variant of "libvndk_ext" can be found.
573 mod := ctx.ModuleForTests("libvndk_ext", coreVariant).Module().(*Module)
574 if extends := mod.getVndkExtendsModuleName(); extends != "libvndk" {
575 t.Errorf("\"libvndk_ext\" must extend from \"libvndk\" but get %q", extends)
576 }
577}
578
579func TestVndkExtError(t *testing.T) {
580 // This test ensures an error is emitted in ill-formed vndk-ext definition.
581 testCcError(t, "must set `vendor: true` to set `extends: \".*\"`", `
582 cc_library {
583 name: "libvndk",
584 vendor_available: true,
585 vndk: {
586 enabled: true,
587 },
588 nocrt: true,
589 }
590
591 cc_library {
592 name: "libvndk_ext",
593 vndk: {
594 enabled: true,
595 extends: "libvndk",
596 },
597 nocrt: true,
598 }
599 `)
600
601 testCcError(t, "must set `extends: \"\\.\\.\\.\"` to vndk extension", `
602 cc_library {
603 name: "libvndk",
604 vendor_available: true,
605 vndk: {
606 enabled: true,
607 },
608 nocrt: true,
609 }
610
611 cc_library {
612 name: "libvndk_ext",
613 vendor: true,
614 vndk: {
615 enabled: true,
616 },
617 nocrt: true,
618 }
619 `)
620}
621
622func TestVndkExtInconsistentSupportSystemProcessError(t *testing.T) {
623 // This test ensures an error is emitted for inconsistent support_system_process.
624 testCcError(t, "module \".*\" with mismatched support_system_process", `
625 cc_library {
626 name: "libvndk",
627 vendor_available: true,
628 vndk: {
629 enabled: true,
630 },
631 nocrt: true,
632 }
633
634 cc_library {
635 name: "libvndk_sp_ext",
636 vendor: true,
637 vndk: {
638 enabled: true,
639 extends: "libvndk",
640 support_system_process: true,
641 },
642 nocrt: true,
643 }
644 `)
645
646 testCcError(t, "module \".*\" with mismatched support_system_process", `
647 cc_library {
648 name: "libvndk_sp",
649 vendor_available: true,
650 vndk: {
651 enabled: true,
652 support_system_process: true,
653 },
654 nocrt: true,
655 }
656
657 cc_library {
658 name: "libvndk_ext",
659 vendor: true,
660 vndk: {
661 enabled: true,
662 extends: "libvndk_sp",
663 },
664 nocrt: true,
665 }
666 `)
667}
668
669func TestVndkExtVendorAvailableFalseError(t *testing.T) {
Logan Chiend3c59a22018-03-29 14:08:15 +0800670 // This test ensures an error is emitted when a VNDK-Ext library extends a VNDK library
Logan Chienf3511742017-10-31 18:04:35 +0800671 // with `vendor_available: false`.
672 testCcError(t, "`extends` refers module \".*\" which does not have `vendor_available: true`", `
673 cc_library {
674 name: "libvndk",
675 vendor_available: false,
676 vndk: {
677 enabled: true,
678 },
679 nocrt: true,
680 }
681
682 cc_library {
683 name: "libvndk_ext",
684 vendor: true,
685 vndk: {
686 enabled: true,
687 extends: "libvndk",
688 },
689 nocrt: true,
690 }
691 `)
692}
693
Logan Chiend3c59a22018-03-29 14:08:15 +0800694func TestVendorModuleUseVndkExt(t *testing.T) {
695 // This test ensures a vendor module can depend on a VNDK-Ext library.
Logan Chienf3511742017-10-31 18:04:35 +0800696 testCc(t, `
697 cc_library {
698 name: "libvndk",
699 vendor_available: true,
700 vndk: {
701 enabled: true,
702 },
703 nocrt: true,
704 }
705
706 cc_library {
707 name: "libvndk_ext",
708 vendor: true,
709 vndk: {
710 enabled: true,
711 extends: "libvndk",
712 },
713 nocrt: true,
714 }
715
716 cc_library {
717
718 name: "libvndk_sp",
719 vendor_available: true,
720 vndk: {
721 enabled: true,
722 support_system_process: true,
723 },
724 nocrt: true,
725 }
726
727 cc_library {
728 name: "libvndk_sp_ext",
729 vendor: true,
730 vndk: {
731 enabled: true,
732 extends: "libvndk_sp",
733 support_system_process: true,
734 },
735 nocrt: true,
736 }
737
738 cc_library {
739 name: "libvendor",
740 vendor: true,
741 shared_libs: ["libvndk_ext", "libvndk_sp_ext"],
742 nocrt: true,
743 }
744 `)
745}
746
Logan Chiend3c59a22018-03-29 14:08:15 +0800747func TestVndkExtUseVendorLib(t *testing.T) {
748 // This test ensures a VNDK-Ext library can depend on a vendor library.
Logan Chienf3511742017-10-31 18:04:35 +0800749 testCc(t, `
750 cc_library {
751 name: "libvndk",
752 vendor_available: true,
753 vndk: {
754 enabled: true,
755 },
756 nocrt: true,
757 }
758
759 cc_library {
760 name: "libvndk_ext",
761 vendor: true,
762 vndk: {
763 enabled: true,
764 extends: "libvndk",
765 },
766 shared_libs: ["libvendor"],
767 nocrt: true,
768 }
769
770 cc_library {
771 name: "libvendor",
772 vendor: true,
773 nocrt: true,
774 }
775 `)
Logan Chienf3511742017-10-31 18:04:35 +0800776
Logan Chiend3c59a22018-03-29 14:08:15 +0800777 // This test ensures a VNDK-SP-Ext library can depend on a vendor library.
778 testCc(t, `
Logan Chienf3511742017-10-31 18:04:35 +0800779 cc_library {
780 name: "libvndk_sp",
781 vendor_available: true,
782 vndk: {
783 enabled: true,
784 support_system_process: true,
785 },
786 nocrt: true,
787 }
788
789 cc_library {
790 name: "libvndk_sp_ext",
791 vendor: true,
792 vndk: {
793 enabled: true,
794 extends: "libvndk_sp",
795 support_system_process: true,
796 },
797 shared_libs: ["libvendor"], // Cause an error
798 nocrt: true,
799 }
800
801 cc_library {
802 name: "libvendor",
803 vendor: true,
804 nocrt: true,
805 }
806 `)
807}
808
Logan Chiend3c59a22018-03-29 14:08:15 +0800809func TestVndkSpExtUseVndkError(t *testing.T) {
810 // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK
811 // library.
812 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
813 cc_library {
814 name: "libvndk",
815 vendor_available: true,
816 vndk: {
817 enabled: true,
818 },
819 nocrt: true,
820 }
821
822 cc_library {
823 name: "libvndk_sp",
824 vendor_available: true,
825 vndk: {
826 enabled: true,
827 support_system_process: true,
828 },
829 nocrt: true,
830 }
831
832 cc_library {
833 name: "libvndk_sp_ext",
834 vendor: true,
835 vndk: {
836 enabled: true,
837 extends: "libvndk_sp",
838 support_system_process: true,
839 },
840 shared_libs: ["libvndk"], // Cause an error
841 nocrt: true,
842 }
843 `)
844
845 // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK-Ext
846 // library.
847 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
848 cc_library {
849 name: "libvndk",
850 vendor_available: true,
851 vndk: {
852 enabled: true,
853 },
854 nocrt: true,
855 }
856
857 cc_library {
858 name: "libvndk_ext",
859 vendor: true,
860 vndk: {
861 enabled: true,
862 extends: "libvndk",
863 },
864 nocrt: true,
865 }
866
867 cc_library {
868 name: "libvndk_sp",
869 vendor_available: true,
870 vndk: {
871 enabled: true,
872 support_system_process: true,
873 },
874 nocrt: true,
875 }
876
877 cc_library {
878 name: "libvndk_sp_ext",
879 vendor: true,
880 vndk: {
881 enabled: true,
882 extends: "libvndk_sp",
883 support_system_process: true,
884 },
885 shared_libs: ["libvndk_ext"], // Cause an error
886 nocrt: true,
887 }
888 `)
889}
890
891func TestVndkUseVndkExtError(t *testing.T) {
892 // This test ensures an error is emitted if a VNDK/VNDK-SP library depends on a
893 // VNDK-Ext/VNDK-SP-Ext library.
Logan Chienf3511742017-10-31 18:04:35 +0800894 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
895 cc_library {
896 name: "libvndk",
897 vendor_available: true,
898 vndk: {
899 enabled: true,
900 },
901 nocrt: true,
902 }
903
904 cc_library {
905 name: "libvndk_ext",
906 vendor: true,
907 vndk: {
908 enabled: true,
909 extends: "libvndk",
910 },
911 nocrt: true,
912 }
913
914 cc_library {
915 name: "libvndk2",
916 vendor_available: true,
917 vndk: {
918 enabled: true,
919 },
920 shared_libs: ["libvndk_ext"],
921 nocrt: true,
922 }
923 `)
924
Martin Stjernholmef449fe2018-11-06 16:12:13 +0000925 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
Logan Chienf3511742017-10-31 18:04:35 +0800926 cc_library {
927 name: "libvndk",
928 vendor_available: true,
929 vndk: {
930 enabled: true,
931 },
932 nocrt: true,
933 }
934
935 cc_library {
936 name: "libvndk_ext",
937 vendor: true,
938 vndk: {
939 enabled: true,
940 extends: "libvndk",
941 },
942 nocrt: true,
943 }
944
945 cc_library {
946 name: "libvndk2",
947 vendor_available: true,
948 vndk: {
949 enabled: true,
950 },
951 target: {
952 vendor: {
953 shared_libs: ["libvndk_ext"],
954 },
955 },
956 nocrt: true,
957 }
958 `)
959
960 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
961 cc_library {
962 name: "libvndk_sp",
963 vendor_available: true,
964 vndk: {
965 enabled: true,
966 support_system_process: true,
967 },
968 nocrt: true,
969 }
970
971 cc_library {
972 name: "libvndk_sp_ext",
973 vendor: true,
974 vndk: {
975 enabled: true,
976 extends: "libvndk_sp",
977 support_system_process: true,
978 },
979 nocrt: true,
980 }
981
982 cc_library {
983 name: "libvndk_sp_2",
984 vendor_available: true,
985 vndk: {
986 enabled: true,
987 support_system_process: true,
988 },
989 shared_libs: ["libvndk_sp_ext"],
990 nocrt: true,
991 }
992 `)
993
Martin Stjernholmef449fe2018-11-06 16:12:13 +0000994 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
Logan Chienf3511742017-10-31 18:04:35 +0800995 cc_library {
996 name: "libvndk_sp",
997 vendor_available: true,
998 vndk: {
999 enabled: true,
1000 },
1001 nocrt: true,
1002 }
1003
1004 cc_library {
1005 name: "libvndk_sp_ext",
1006 vendor: true,
1007 vndk: {
1008 enabled: true,
1009 extends: "libvndk_sp",
1010 },
1011 nocrt: true,
1012 }
1013
1014 cc_library {
1015 name: "libvndk_sp2",
1016 vendor_available: true,
1017 vndk: {
1018 enabled: true,
1019 },
1020 target: {
1021 vendor: {
1022 shared_libs: ["libvndk_sp_ext"],
1023 },
1024 },
1025 nocrt: true,
1026 }
1027 `)
1028}
1029
Colin Cross0af4b842015-04-30 16:36:18 -07001030var (
1031 str11 = "01234567891"
1032 str10 = str11[:10]
1033 str9 = str11[:9]
1034 str5 = str11[:5]
1035 str4 = str11[:4]
1036)
1037
1038var splitListForSizeTestCases = []struct {
1039 in []string
1040 out [][]string
1041 size int
1042}{
1043 {
1044 in: []string{str10},
1045 out: [][]string{{str10}},
1046 size: 10,
1047 },
1048 {
1049 in: []string{str9},
1050 out: [][]string{{str9}},
1051 size: 10,
1052 },
1053 {
1054 in: []string{str5},
1055 out: [][]string{{str5}},
1056 size: 10,
1057 },
1058 {
1059 in: []string{str11},
1060 out: nil,
1061 size: 10,
1062 },
1063 {
1064 in: []string{str10, str10},
1065 out: [][]string{{str10}, {str10}},
1066 size: 10,
1067 },
1068 {
1069 in: []string{str9, str10},
1070 out: [][]string{{str9}, {str10}},
1071 size: 10,
1072 },
1073 {
1074 in: []string{str10, str9},
1075 out: [][]string{{str10}, {str9}},
1076 size: 10,
1077 },
1078 {
1079 in: []string{str5, str4},
1080 out: [][]string{{str5, str4}},
1081 size: 10,
1082 },
1083 {
1084 in: []string{str5, str4, str5},
1085 out: [][]string{{str5, str4}, {str5}},
1086 size: 10,
1087 },
1088 {
1089 in: []string{str5, str4, str5, str4},
1090 out: [][]string{{str5, str4}, {str5, str4}},
1091 size: 10,
1092 },
1093 {
1094 in: []string{str5, str4, str5, str5},
1095 out: [][]string{{str5, str4}, {str5}, {str5}},
1096 size: 10,
1097 },
1098 {
1099 in: []string{str5, str5, str5, str4},
1100 out: [][]string{{str5}, {str5}, {str5, str4}},
1101 size: 10,
1102 },
1103 {
1104 in: []string{str9, str11},
1105 out: nil,
1106 size: 10,
1107 },
1108 {
1109 in: []string{str11, str9},
1110 out: nil,
1111 size: 10,
1112 },
1113}
1114
1115func TestSplitListForSize(t *testing.T) {
1116 for _, testCase := range splitListForSizeTestCases {
Colin Cross5b529592017-05-09 13:34:34 -07001117 out, _ := splitListForSize(android.PathsForTesting(testCase.in), testCase.size)
1118
1119 var outStrings [][]string
1120
1121 if len(out) > 0 {
1122 outStrings = make([][]string, len(out))
1123 for i, o := range out {
1124 outStrings[i] = o.Strings()
1125 }
1126 }
1127
1128 if !reflect.DeepEqual(outStrings, testCase.out) {
Colin Cross0af4b842015-04-30 16:36:18 -07001129 t.Errorf("incorrect output:")
1130 t.Errorf(" input: %#v", testCase.in)
1131 t.Errorf(" size: %d", testCase.size)
1132 t.Errorf(" expected: %#v", testCase.out)
Colin Cross5b529592017-05-09 13:34:34 -07001133 t.Errorf(" got: %#v", outStrings)
Colin Cross0af4b842015-04-30 16:36:18 -07001134 }
1135 }
1136}
Jeff Gaston294356f2017-09-27 17:05:30 -07001137
1138var staticLinkDepOrderTestCases = []struct {
1139 // This is a string representation of a map[moduleName][]moduleDependency .
1140 // It models the dependencies declared in an Android.bp file.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001141 inStatic string
1142
1143 // This is a string representation of a map[moduleName][]moduleDependency .
1144 // It models the dependencies declared in an Android.bp file.
1145 inShared string
Jeff Gaston294356f2017-09-27 17:05:30 -07001146
1147 // allOrdered is a string representation of a map[moduleName][]moduleDependency .
1148 // The keys of allOrdered specify which modules we would like to check.
1149 // The values of allOrdered specify the expected result (of the transitive closure of all
1150 // dependencies) for each module to test
1151 allOrdered string
1152
1153 // outOrdered is a string representation of a map[moduleName][]moduleDependency .
1154 // The keys of outOrdered specify which modules we would like to check.
1155 // The values of outOrdered specify the expected result (of the ordered linker command line)
1156 // for each module to test.
1157 outOrdered string
1158}{
1159 // Simple tests
1160 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001161 inStatic: "",
Jeff Gaston294356f2017-09-27 17:05:30 -07001162 outOrdered: "",
1163 },
1164 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001165 inStatic: "a:",
Jeff Gaston294356f2017-09-27 17:05:30 -07001166 outOrdered: "a:",
1167 },
1168 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001169 inStatic: "a:b; b:",
Jeff Gaston294356f2017-09-27 17:05:30 -07001170 outOrdered: "a:b; b:",
1171 },
1172 // Tests of reordering
1173 {
1174 // diamond example
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001175 inStatic: "a:d,b,c; b:d; c:d; d:",
Jeff Gaston294356f2017-09-27 17:05:30 -07001176 outOrdered: "a:b,c,d; b:d; c:d; d:",
1177 },
1178 {
1179 // somewhat real example
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001180 inStatic: "bsdiff_unittest:b,c,d,e,f,g,h,i; e:b",
Jeff Gaston294356f2017-09-27 17:05:30 -07001181 outOrdered: "bsdiff_unittest:c,d,e,b,f,g,h,i; e:b",
1182 },
1183 {
1184 // multiple reorderings
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001185 inStatic: "a:b,c,d,e; d:b; e:c",
Jeff Gaston294356f2017-09-27 17:05:30 -07001186 outOrdered: "a:d,b,e,c; d:b; e:c",
1187 },
1188 {
1189 // should reorder without adding new transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001190 inStatic: "bin:lib2,lib1; lib1:lib2,liboptional",
Jeff Gaston294356f2017-09-27 17:05:30 -07001191 allOrdered: "bin:lib1,lib2,liboptional; lib1:lib2,liboptional",
1192 outOrdered: "bin:lib1,lib2; lib1:lib2,liboptional",
1193 },
1194 {
1195 // multiple levels of dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001196 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 -07001197 allOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d",
1198 outOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d",
1199 },
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001200 // shared dependencies
1201 {
1202 // Note that this test doesn't recurse, to minimize the amount of logic it tests.
1203 // So, we don't actually have to check that a shared dependency of c will change the order
1204 // of a library that depends statically on b and on c. We only need to check that if c has
1205 // a shared dependency on b, that that shows up in allOrdered.
1206 inShared: "c:b",
1207 allOrdered: "c:b",
1208 outOrdered: "c:",
1209 },
1210 {
1211 // This test doesn't actually include any shared dependencies but it's a reminder of what
1212 // the second phase of the above test would look like
1213 inStatic: "a:b,c; c:b",
1214 allOrdered: "a:c,b; c:b",
1215 outOrdered: "a:c,b; c:b",
1216 },
Jeff Gaston294356f2017-09-27 17:05:30 -07001217 // tiebreakers for when two modules specifying different orderings and there is no dependency
1218 // to dictate an order
1219 {
1220 // 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 -08001221 inStatic: "a1:b,c,d,e; a2:b,c,e,d; b:d,e; c:e,d",
Jeff Gaston294356f2017-09-27 17:05:30 -07001222 outOrdered: "a1:b,c,d,e; a2:b,c,e,d; b:d,e; c:e,d",
1223 },
1224 {
1225 // 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 -08001226 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 -07001227 outOrdered: "a1:b1,c1,e,d; b1:d,e; c1:e,d; a2:b2,c2,d,e; b2:d,e; c2:d,e",
1228 },
1229 // Tests involving duplicate dependencies
1230 {
1231 // simple duplicate
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001232 inStatic: "a:b,c,c,b",
Jeff Gaston294356f2017-09-27 17:05:30 -07001233 outOrdered: "a:c,b",
1234 },
1235 {
1236 // duplicates with reordering
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001237 inStatic: "a:b,c,d,c; c:b",
Jeff Gaston294356f2017-09-27 17:05:30 -07001238 outOrdered: "a:d,c,b",
1239 },
1240 // Tests to confirm the nonexistence of infinite loops.
1241 // These cases should never happen, so as long as the test terminates and the
1242 // result is deterministic then that should be fine.
1243 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001244 inStatic: "a:a",
Jeff Gaston294356f2017-09-27 17:05:30 -07001245 outOrdered: "a:a",
1246 },
1247 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001248 inStatic: "a:b; b:c; c:a",
Jeff Gaston294356f2017-09-27 17:05:30 -07001249 allOrdered: "a:b,c; b:c,a; c:a,b",
1250 outOrdered: "a:b; b:c; c:a",
1251 },
1252 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001253 inStatic: "a:b,c; b:c,a; c:a,b",
Jeff Gaston294356f2017-09-27 17:05:30 -07001254 allOrdered: "a:c,a,b; b:a,b,c; c:b,c,a",
1255 outOrdered: "a:c,b; b:a,c; c:b,a",
1256 },
1257}
1258
1259// converts from a string like "a:b,c; d:e" to (["a","b"], {"a":["b","c"], "d":["e"]}, [{"a", "a.o"}, {"b", "b.o"}])
1260func parseModuleDeps(text string) (modulesInOrder []android.Path, allDeps map[android.Path][]android.Path) {
1261 // convert from "a:b,c; d:e" to "a:b,c;d:e"
1262 strippedText := strings.Replace(text, " ", "", -1)
1263 if len(strippedText) < 1 {
1264 return []android.Path{}, make(map[android.Path][]android.Path, 0)
1265 }
1266 allDeps = make(map[android.Path][]android.Path, 0)
1267
1268 // convert from "a:b,c;d:e" to ["a:b,c", "d:e"]
1269 moduleTexts := strings.Split(strippedText, ";")
1270
1271 outputForModuleName := func(moduleName string) android.Path {
1272 return android.PathForTesting(moduleName)
1273 }
1274
1275 for _, moduleText := range moduleTexts {
1276 // convert from "a:b,c" to ["a", "b,c"]
1277 components := strings.Split(moduleText, ":")
1278 if len(components) != 2 {
1279 panic(fmt.Sprintf("illegal module dep string %q from larger string %q; must contain one ':', not %v", moduleText, text, len(components)-1))
1280 }
1281 moduleName := components[0]
1282 moduleOutput := outputForModuleName(moduleName)
1283 modulesInOrder = append(modulesInOrder, moduleOutput)
1284
1285 depString := components[1]
1286 // convert from "b,c" to ["b", "c"]
1287 depNames := strings.Split(depString, ",")
1288 if len(depString) < 1 {
1289 depNames = []string{}
1290 }
1291 var deps []android.Path
1292 for _, depName := range depNames {
1293 deps = append(deps, outputForModuleName(depName))
1294 }
1295 allDeps[moduleOutput] = deps
1296 }
1297 return modulesInOrder, allDeps
1298}
1299
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001300func TestLinkReordering(t *testing.T) {
Jeff Gaston294356f2017-09-27 17:05:30 -07001301 for _, testCase := range staticLinkDepOrderTestCases {
1302 errs := []string{}
1303
1304 // parse testcase
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001305 _, givenTransitiveDeps := parseModuleDeps(testCase.inStatic)
Jeff Gaston294356f2017-09-27 17:05:30 -07001306 expectedModuleNames, expectedTransitiveDeps := parseModuleDeps(testCase.outOrdered)
1307 if testCase.allOrdered == "" {
1308 // allow the test case to skip specifying allOrdered
1309 testCase.allOrdered = testCase.outOrdered
1310 }
1311 _, expectedAllDeps := parseModuleDeps(testCase.allOrdered)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001312 _, givenAllSharedDeps := parseModuleDeps(testCase.inShared)
Jeff Gaston294356f2017-09-27 17:05:30 -07001313
1314 // For each module whose post-reordered dependencies were specified, validate that
1315 // reordering the inputs produces the expected outputs.
1316 for _, moduleName := range expectedModuleNames {
1317 moduleDeps := givenTransitiveDeps[moduleName]
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001318 givenSharedDeps := givenAllSharedDeps[moduleName]
1319 orderedAllDeps, orderedDeclaredDeps := orderDeps(moduleDeps, givenSharedDeps, givenTransitiveDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001320
1321 correctAllOrdered := expectedAllDeps[moduleName]
1322 if !reflect.DeepEqual(orderedAllDeps, correctAllOrdered) {
1323 errs = append(errs, fmt.Sprintf("orderDeps returned incorrect orderedAllDeps."+
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001324 "\nin static:%q"+
1325 "\nin shared:%q"+
Jeff Gaston294356f2017-09-27 17:05:30 -07001326 "\nmodule: %v"+
1327 "\nexpected: %s"+
1328 "\nactual: %s",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001329 testCase.inStatic, testCase.inShared, moduleName, correctAllOrdered, orderedAllDeps))
Jeff Gaston294356f2017-09-27 17:05:30 -07001330 }
1331
1332 correctOutputDeps := expectedTransitiveDeps[moduleName]
1333 if !reflect.DeepEqual(correctOutputDeps, orderedDeclaredDeps) {
1334 errs = append(errs, fmt.Sprintf("orderDeps returned incorrect orderedDeclaredDeps."+
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001335 "\nin static:%q"+
1336 "\nin shared:%q"+
Jeff Gaston294356f2017-09-27 17:05:30 -07001337 "\nmodule: %v"+
1338 "\nexpected: %s"+
1339 "\nactual: %s",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001340 testCase.inStatic, testCase.inShared, moduleName, correctOutputDeps, orderedDeclaredDeps))
Jeff Gaston294356f2017-09-27 17:05:30 -07001341 }
1342 }
1343
1344 if len(errs) > 0 {
1345 sort.Strings(errs)
1346 for _, err := range errs {
1347 t.Error(err)
1348 }
1349 }
1350 }
1351}
Logan Chienf3511742017-10-31 18:04:35 +08001352
Jeff Gaston294356f2017-09-27 17:05:30 -07001353func getOutputPaths(ctx *android.TestContext, variant string, moduleNames []string) (paths android.Paths) {
1354 for _, moduleName := range moduleNames {
1355 module := ctx.ModuleForTests(moduleName, variant).Module().(*Module)
1356 output := module.outputFile.Path()
1357 paths = append(paths, output)
1358 }
1359 return paths
1360}
1361
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001362func TestStaticLibDepReordering(t *testing.T) {
Jeff Gaston294356f2017-09-27 17:05:30 -07001363 ctx := testCc(t, `
1364 cc_library {
1365 name: "a",
1366 static_libs: ["b", "c", "d"],
Jiyong Park374510b2018-03-19 18:23:01 +09001367 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07001368 }
1369 cc_library {
1370 name: "b",
Jiyong Park374510b2018-03-19 18:23:01 +09001371 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07001372 }
1373 cc_library {
1374 name: "c",
1375 static_libs: ["b"],
Jiyong Park374510b2018-03-19 18:23:01 +09001376 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07001377 }
1378 cc_library {
1379 name: "d",
Jiyong Park374510b2018-03-19 18:23:01 +09001380 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07001381 }
1382
1383 `)
1384
1385 variant := "android_arm64_armv8-a_core_static"
1386 moduleA := ctx.ModuleForTests("a", variant).Module().(*Module)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001387 actual := moduleA.depsInLinkOrder
Jeff Gaston294356f2017-09-27 17:05:30 -07001388 expected := getOutputPaths(ctx, variant, []string{"c", "b", "d"})
1389
1390 if !reflect.DeepEqual(actual, expected) {
1391 t.Errorf("staticDeps orderings were not propagated correctly"+
1392 "\nactual: %v"+
1393 "\nexpected: %v",
1394 actual,
1395 expected,
1396 )
1397 }
Jiyong Parkd08b6972017-09-26 10:50:54 +09001398}
Jeff Gaston294356f2017-09-27 17:05:30 -07001399
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001400func TestStaticLibDepReorderingWithShared(t *testing.T) {
1401 ctx := testCc(t, `
1402 cc_library {
1403 name: "a",
1404 static_libs: ["b", "c"],
Jiyong Park374510b2018-03-19 18:23:01 +09001405 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001406 }
1407 cc_library {
1408 name: "b",
Jiyong Park374510b2018-03-19 18:23:01 +09001409 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001410 }
1411 cc_library {
1412 name: "c",
1413 shared_libs: ["b"],
Jiyong Park374510b2018-03-19 18:23:01 +09001414 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001415 }
1416
1417 `)
1418
1419 variant := "android_arm64_armv8-a_core_static"
1420 moduleA := ctx.ModuleForTests("a", variant).Module().(*Module)
1421 actual := moduleA.depsInLinkOrder
1422 expected := getOutputPaths(ctx, variant, []string{"c", "b"})
1423
1424 if !reflect.DeepEqual(actual, expected) {
1425 t.Errorf("staticDeps orderings did not account for shared libs"+
1426 "\nactual: %v"+
1427 "\nexpected: %v",
1428 actual,
1429 expected,
1430 )
1431 }
1432}
1433
Jiyong Parka46a4d52017-12-14 19:54:34 +09001434func TestLlndkHeaders(t *testing.T) {
1435 ctx := testCc(t, `
1436 llndk_headers {
1437 name: "libllndk_headers",
1438 export_include_dirs: ["my_include"],
1439 }
1440 llndk_library {
1441 name: "libllndk",
1442 export_llndk_headers: ["libllndk_headers"],
1443 }
1444 cc_library {
1445 name: "libvendor",
1446 shared_libs: ["libllndk"],
1447 vendor: true,
1448 srcs: ["foo.c"],
Logan Chienf3511742017-10-31 18:04:35 +08001449 no_libgcc: true,
1450 nocrt: true,
Jiyong Parka46a4d52017-12-14 19:54:34 +09001451 }
1452 `)
1453
1454 // _static variant is used since _shared reuses *.o from the static variant
1455 cc := ctx.ModuleForTests("libvendor", "android_arm_armv7-a-neon_vendor_static").Rule("cc")
1456 cflags := cc.Args["cFlags"]
1457 if !strings.Contains(cflags, "-Imy_include") {
1458 t.Errorf("cflags for libvendor must contain -Imy_include, but was %#v.", cflags)
1459 }
1460}
1461
Logan Chien43d34c32017-12-20 01:17:32 +08001462func checkRuntimeLibs(t *testing.T, expected []string, module *Module) {
1463 actual := module.Properties.AndroidMkRuntimeLibs
1464 if !reflect.DeepEqual(actual, expected) {
1465 t.Errorf("incorrect runtime_libs for shared libs"+
1466 "\nactual: %v"+
1467 "\nexpected: %v",
1468 actual,
1469 expected,
1470 )
1471 }
1472}
1473
1474const runtimeLibAndroidBp = `
1475 cc_library {
1476 name: "libvendor_available1",
1477 vendor_available: true,
1478 no_libgcc : true,
1479 nocrt : true,
1480 system_shared_libs : [],
1481 }
1482 cc_library {
1483 name: "libvendor_available2",
1484 vendor_available: true,
1485 runtime_libs: ["libvendor_available1"],
1486 no_libgcc : true,
1487 nocrt : true,
1488 system_shared_libs : [],
1489 }
1490 cc_library {
1491 name: "libvendor_available3",
1492 vendor_available: true,
1493 runtime_libs: ["libvendor_available1"],
1494 target: {
1495 vendor: {
1496 exclude_runtime_libs: ["libvendor_available1"],
1497 }
1498 },
1499 no_libgcc : true,
1500 nocrt : true,
1501 system_shared_libs : [],
1502 }
1503 cc_library {
1504 name: "libcore",
1505 runtime_libs: ["libvendor_available1"],
1506 no_libgcc : true,
1507 nocrt : true,
1508 system_shared_libs : [],
1509 }
1510 cc_library {
1511 name: "libvendor1",
1512 vendor: true,
1513 no_libgcc : true,
1514 nocrt : true,
1515 system_shared_libs : [],
1516 }
1517 cc_library {
1518 name: "libvendor2",
1519 vendor: true,
1520 runtime_libs: ["libvendor_available1", "libvendor1"],
1521 no_libgcc : true,
1522 nocrt : true,
1523 system_shared_libs : [],
1524 }
1525`
1526
1527func TestRuntimeLibs(t *testing.T) {
1528 ctx := testCc(t, runtimeLibAndroidBp)
1529
1530 // runtime_libs for core variants use the module names without suffixes.
1531 variant := "android_arm64_armv8-a_core_shared"
1532
1533 module := ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module)
1534 checkRuntimeLibs(t, []string{"libvendor_available1"}, module)
1535
1536 module = ctx.ModuleForTests("libcore", variant).Module().(*Module)
1537 checkRuntimeLibs(t, []string{"libvendor_available1"}, module)
1538
1539 // runtime_libs for vendor variants have '.vendor' suffixes if the modules have both core
1540 // and vendor variants.
1541 variant = "android_arm64_armv8-a_vendor_shared"
1542
1543 module = ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module)
1544 checkRuntimeLibs(t, []string{"libvendor_available1.vendor"}, module)
1545
1546 module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module)
1547 checkRuntimeLibs(t, []string{"libvendor_available1.vendor", "libvendor1"}, module)
1548}
1549
1550func TestExcludeRuntimeLibs(t *testing.T) {
1551 ctx := testCc(t, runtimeLibAndroidBp)
1552
1553 variant := "android_arm64_armv8-a_core_shared"
1554 module := ctx.ModuleForTests("libvendor_available3", variant).Module().(*Module)
1555 checkRuntimeLibs(t, []string{"libvendor_available1"}, module)
1556
1557 variant = "android_arm64_armv8-a_vendor_shared"
1558 module = ctx.ModuleForTests("libvendor_available3", variant).Module().(*Module)
1559 checkRuntimeLibs(t, nil, module)
1560}
1561
1562func TestRuntimeLibsNoVndk(t *testing.T) {
1563 ctx := testCcNoVndk(t, runtimeLibAndroidBp)
1564
1565 // If DeviceVndkVersion is not defined, then runtime_libs are copied as-is.
1566
1567 variant := "android_arm64_armv8-a_core_shared"
1568
1569 module := ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module)
1570 checkRuntimeLibs(t, []string{"libvendor_available1"}, module)
1571
1572 module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module)
1573 checkRuntimeLibs(t, []string{"libvendor_available1", "libvendor1"}, module)
1574}
1575
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00001576func checkStaticLibs(t *testing.T, expected []string, module *Module) {
1577 actual := module.Properties.AndroidMkStaticLibs
1578 if !reflect.DeepEqual(actual, expected) {
1579 t.Errorf("incorrect static_libs"+
1580 "\nactual: %v"+
1581 "\nexpected: %v",
1582 actual,
1583 expected,
1584 )
1585 }
1586}
1587
1588const staticLibAndroidBp = `
1589 cc_library {
1590 name: "lib1",
1591 }
1592 cc_library {
1593 name: "lib2",
1594 static_libs: ["lib1"],
1595 }
1596`
1597
1598func TestStaticLibDepExport(t *testing.T) {
1599 ctx := testCc(t, staticLibAndroidBp)
1600
1601 // Check the shared version of lib2.
1602 variant := "android_arm64_armv8-a_core_shared"
1603 module := ctx.ModuleForTests("lib2", variant).Module().(*Module)
1604 checkStaticLibs(t, []string{"lib1", "libclang_rt.builtins-aarch64-android", "libatomic", "libgcc"}, module)
1605
1606 // Check the static version of lib2.
1607 variant = "android_arm64_armv8-a_core_static"
1608 module = ctx.ModuleForTests("lib2", variant).Module().(*Module)
1609 // libc++_static is linked additionally.
1610 checkStaticLibs(t, []string{"lib1", "libc++_static", "libclang_rt.builtins-aarch64-android", "libatomic", "libgcc"}, module)
1611}
1612
Jiyong Parkd08b6972017-09-26 10:50:54 +09001613var compilerFlagsTestCases = []struct {
1614 in string
1615 out bool
1616}{
1617 {
1618 in: "a",
1619 out: false,
1620 },
1621 {
1622 in: "-a",
1623 out: true,
1624 },
1625 {
1626 in: "-Ipath/to/something",
1627 out: false,
1628 },
1629 {
1630 in: "-isystempath/to/something",
1631 out: false,
1632 },
1633 {
1634 in: "--coverage",
1635 out: false,
1636 },
1637 {
1638 in: "-include a/b",
1639 out: true,
1640 },
1641 {
1642 in: "-include a/b c/d",
1643 out: false,
1644 },
1645 {
1646 in: "-DMACRO",
1647 out: true,
1648 },
1649 {
1650 in: "-DMAC RO",
1651 out: false,
1652 },
1653 {
1654 in: "-a -b",
1655 out: false,
1656 },
1657 {
1658 in: "-DMACRO=definition",
1659 out: true,
1660 },
1661 {
1662 in: "-DMACRO=defi nition",
1663 out: true, // TODO(jiyong): this should be false
1664 },
1665 {
1666 in: "-DMACRO(x)=x + 1",
1667 out: true,
1668 },
1669 {
1670 in: "-DMACRO=\"defi nition\"",
1671 out: true,
1672 },
1673}
1674
1675type mockContext struct {
1676 BaseModuleContext
1677 result bool
1678}
1679
1680func (ctx *mockContext) PropertyErrorf(property, format string, args ...interface{}) {
1681 // CheckBadCompilerFlags calls this function when the flag should be rejected
1682 ctx.result = false
1683}
1684
1685func TestCompilerFlags(t *testing.T) {
1686 for _, testCase := range compilerFlagsTestCases {
1687 ctx := &mockContext{result: true}
1688 CheckBadCompilerFlags(ctx, "", []string{testCase.in})
1689 if ctx.result != testCase.out {
1690 t.Errorf("incorrect output:")
1691 t.Errorf(" input: %#v", testCase.in)
1692 t.Errorf(" expected: %#v", testCase.out)
1693 t.Errorf(" got: %#v", ctx.result)
1694 }
1695 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001696}
Jiyong Park374510b2018-03-19 18:23:01 +09001697
1698func TestVendorPublicLibraries(t *testing.T) {
1699 ctx := testCc(t, `
1700 cc_library_headers {
1701 name: "libvendorpublic_headers",
1702 export_include_dirs: ["my_include"],
1703 }
1704 vendor_public_library {
1705 name: "libvendorpublic",
1706 symbol_file: "",
1707 export_public_headers: ["libvendorpublic_headers"],
1708 }
1709 cc_library {
1710 name: "libvendorpublic",
1711 srcs: ["foo.c"],
1712 vendor: true,
1713 no_libgcc: true,
1714 nocrt: true,
1715 }
1716
1717 cc_library {
1718 name: "libsystem",
1719 shared_libs: ["libvendorpublic"],
1720 vendor: false,
1721 srcs: ["foo.c"],
1722 no_libgcc: true,
1723 nocrt: true,
1724 }
1725 cc_library {
1726 name: "libvendor",
1727 shared_libs: ["libvendorpublic"],
1728 vendor: true,
1729 srcs: ["foo.c"],
1730 no_libgcc: true,
1731 nocrt: true,
1732 }
1733 `)
1734
1735 variant := "android_arm64_armv8-a_core_shared"
1736
1737 // test if header search paths are correctly added
1738 // _static variant is used since _shared reuses *.o from the static variant
1739 cc := ctx.ModuleForTests("libsystem", strings.Replace(variant, "_shared", "_static", 1)).Rule("cc")
1740 cflags := cc.Args["cFlags"]
1741 if !strings.Contains(cflags, "-Imy_include") {
1742 t.Errorf("cflags for libsystem must contain -Imy_include, but was %#v.", cflags)
1743 }
1744
1745 // test if libsystem is linked to the stub
1746 ld := ctx.ModuleForTests("libsystem", variant).Rule("ld")
1747 libflags := ld.Args["libFlags"]
1748 stubPaths := getOutputPaths(ctx, variant, []string{"libvendorpublic" + vendorPublicLibrarySuffix})
1749 if !strings.Contains(libflags, stubPaths[0].String()) {
1750 t.Errorf("libflags for libsystem must contain %#v, but was %#v", stubPaths[0], libflags)
1751 }
1752
1753 // test if libvendor is linked to the real shared lib
1754 ld = ctx.ModuleForTests("libvendor", strings.Replace(variant, "_core", "_vendor", 1)).Rule("ld")
1755 libflags = ld.Args["libFlags"]
1756 stubPaths = getOutputPaths(ctx, strings.Replace(variant, "_core", "_vendor", 1), []string{"libvendorpublic"})
1757 if !strings.Contains(libflags, stubPaths[0].String()) {
1758 t.Errorf("libflags for libvendor must contain %#v, but was %#v", stubPaths[0], libflags)
1759 }
1760
1761}
Jiyong Park37b25202018-07-11 10:49:27 +09001762
1763func TestRecovery(t *testing.T) {
1764 ctx := testCc(t, `
1765 cc_library_shared {
1766 name: "librecovery",
1767 recovery: true,
1768 }
1769 cc_library_shared {
1770 name: "librecovery32",
1771 recovery: true,
1772 compile_multilib:"32",
1773 }
Jiyong Park5baac542018-08-28 09:55:37 +09001774 cc_library_shared {
1775 name: "libHalInRecovery",
1776 recovery_available: true,
1777 vendor: true,
1778 }
Jiyong Park37b25202018-07-11 10:49:27 +09001779 `)
1780
1781 variants := ctx.ModuleVariantsForTests("librecovery")
1782 const arm64 = "android_arm64_armv8-a_recovery_shared"
1783 if len(variants) != 1 || !android.InList(arm64, variants) {
1784 t.Errorf("variants of librecovery must be \"%s\" only, but was %#v", arm64, variants)
1785 }
1786
1787 variants = ctx.ModuleVariantsForTests("librecovery32")
1788 if android.InList(arm64, variants) {
1789 t.Errorf("multilib was set to 32 for librecovery32, but its variants has %s.", arm64)
1790 }
Jiyong Park5baac542018-08-28 09:55:37 +09001791
1792 recoveryModule := ctx.ModuleForTests("libHalInRecovery", recoveryVariant).Module().(*Module)
1793 if !recoveryModule.Platform() {
1794 t.Errorf("recovery variant of libHalInRecovery must not specific to device, soc, or product")
1795 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09001796}
Jiyong Park5baac542018-08-28 09:55:37 +09001797
Jiyong Park7ed9de32018-10-15 22:25:07 +09001798func TestVersionedStubs(t *testing.T) {
1799 ctx := testCc(t, `
1800 cc_library_shared {
1801 name: "libFoo",
Jiyong Parkda732bd2018-11-02 18:23:15 +09001802 srcs: ["foo.c"],
Jiyong Park7ed9de32018-10-15 22:25:07 +09001803 stubs: {
1804 symbol_file: "foo.map.txt",
1805 versions: ["1", "2", "3"],
1806 },
1807 }
Jiyong Parkda732bd2018-11-02 18:23:15 +09001808
Jiyong Park7ed9de32018-10-15 22:25:07 +09001809 cc_library_shared {
1810 name: "libBar",
Jiyong Parkda732bd2018-11-02 18:23:15 +09001811 srcs: ["bar.c"],
Jiyong Park7ed9de32018-10-15 22:25:07 +09001812 shared_libs: ["libFoo#1"],
1813 }`)
1814
1815 variants := ctx.ModuleVariantsForTests("libFoo")
1816 expectedVariants := []string{
1817 "android_arm64_armv8-a_core_shared",
1818 "android_arm64_armv8-a_core_shared_1",
1819 "android_arm64_armv8-a_core_shared_2",
1820 "android_arm64_armv8-a_core_shared_3",
1821 "android_arm_armv7-a-neon_core_shared",
1822 "android_arm_armv7-a-neon_core_shared_1",
1823 "android_arm_armv7-a-neon_core_shared_2",
1824 "android_arm_armv7-a-neon_core_shared_3",
1825 }
1826 variantsMismatch := false
1827 if len(variants) != len(expectedVariants) {
1828 variantsMismatch = true
1829 } else {
1830 for _, v := range expectedVariants {
1831 if !inList(v, variants) {
1832 variantsMismatch = false
1833 }
1834 }
1835 }
1836 if variantsMismatch {
1837 t.Errorf("variants of libFoo expected:\n")
1838 for _, v := range expectedVariants {
1839 t.Errorf("%q\n", v)
1840 }
1841 t.Errorf(", but got:\n")
1842 for _, v := range variants {
1843 t.Errorf("%q\n", v)
1844 }
1845 }
1846
1847 libBarLinkRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_core_shared").Rule("ld")
1848 libFlags := libBarLinkRule.Args["libFlags"]
1849 libFoo1StubPath := "libFoo/android_arm64_armv8-a_core_shared_1/libFoo.so"
1850 if !strings.Contains(libFlags, libFoo1StubPath) {
1851 t.Errorf("%q is not found in %q", libFoo1StubPath, libFlags)
1852 }
Jiyong Parkda732bd2018-11-02 18:23:15 +09001853
1854 libBarCompileRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_core_shared").Rule("cc")
1855 cFlags := libBarCompileRule.Args["cFlags"]
1856 libFoo1VersioningMacro := "-D__LIBFOO_API__=1"
1857 if !strings.Contains(cFlags, libFoo1VersioningMacro) {
1858 t.Errorf("%q is not found in %q", libFoo1VersioningMacro, cFlags)
1859 }
Jiyong Park37b25202018-07-11 10:49:27 +09001860}
Jaewoong Jung232c07c2018-12-18 11:08:25 -08001861
1862func TestStaticExecutable(t *testing.T) {
1863 ctx := testCc(t, `
1864 cc_binary {
1865 name: "static_test",
1866 srcs: ["foo.c"],
1867 static_executable: true,
1868 }`)
1869
1870 variant := "android_arm64_armv8-a_core"
1871 binModuleRule := ctx.ModuleForTests("static_test", variant).Rule("ld")
1872 libFlags := binModuleRule.Args["libFlags"]
1873 systemStaticLibs := []string{"libc.a", "libm.a", "libdl.a"}
1874 for _, lib := range systemStaticLibs {
1875 if !strings.Contains(libFlags, lib) {
1876 t.Errorf("Static lib %q was not found in %q", lib, libFlags)
1877 }
1878 }
1879 systemSharedLibs := []string{"libc.so", "libm.so", "libdl.so"}
1880 for _, lib := range systemSharedLibs {
1881 if strings.Contains(libFlags, lib) {
1882 t.Errorf("Shared lib %q was found in %q", lib, libFlags)
1883 }
1884 }
1885}