blob: 808968cf8a01a6b36eee304030b5efea881403ee [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 (
Jeff Gaston294356f2017-09-27 17:05:30 -070018 "fmt"
Jiyong Park6a43f042017-10-12 23:05:00 +090019 "io/ioutil"
20 "os"
Inseob Kim1f086e22019-05-09 13:29:15 +090021 "path/filepath"
Colin Cross74d1ec02015-04-28 13:30:13 -070022 "reflect"
Jeff Gaston294356f2017-09-27 17:05:30 -070023 "sort"
24 "strings"
Colin Cross74d1ec02015-04-28 13:30:13 -070025 "testing"
Colin Crosse1bb5d02019-09-24 14:55:04 -070026
27 "android/soong/android"
Colin Cross74d1ec02015-04-28 13:30:13 -070028)
29
Jiyong Park6a43f042017-10-12 23:05:00 +090030var buildDir string
31
32func setUp() {
33 var err error
34 buildDir, err = ioutil.TempDir("", "soong_cc_test")
35 if err != nil {
36 panic(err)
37 }
38}
39
40func tearDown() {
41 os.RemoveAll(buildDir)
42}
43
44func TestMain(m *testing.M) {
45 run := func() int {
46 setUp()
47 defer tearDown()
48
49 return m.Run()
50 }
51
52 os.Exit(run())
53}
54
Logan Chienf3511742017-10-31 18:04:35 +080055func testCcWithConfig(t *testing.T, bp string, config android.Config) *android.TestContext {
Colin Crosse1bb5d02019-09-24 14:55:04 -070056 t.Helper()
Doug Hornc32c6b02019-01-17 14:44:05 -080057 return testCcWithConfigForOs(t, bp, config, android.Android)
58}
59
60func testCcWithConfigForOs(t *testing.T, bp string, config android.Config, os android.OsType) *android.TestContext {
Logan Chiend3c59a22018-03-29 14:08:15 +080061 t.Helper()
Colin Cross9a942872019-05-14 15:44:26 -070062 ctx := CreateTestContext(bp, nil, os)
Colin Cross33b2fb72019-05-14 14:07:01 -070063 ctx.Register()
Logan Chienf3511742017-10-31 18:04:35 +080064
Jeff Gastond3e141d2017-08-08 17:46:01 -070065 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
Logan Chien42039712018-03-12 16:29:17 +080066 android.FailIfErrored(t, errs)
Jiyong Park6a43f042017-10-12 23:05:00 +090067 _, errs = ctx.PrepareBuildActions(config)
Logan Chien42039712018-03-12 16:29:17 +080068 android.FailIfErrored(t, errs)
Jiyong Park6a43f042017-10-12 23:05:00 +090069
70 return ctx
71}
72
Logan Chienf3511742017-10-31 18:04:35 +080073func testCc(t *testing.T, bp string) *android.TestContext {
Logan Chiend3c59a22018-03-29 14:08:15 +080074 t.Helper()
Logan Chienf3511742017-10-31 18:04:35 +080075 config := android.TestArchConfig(buildDir, nil)
Dan Willemsen674dc7f2018-03-12 18:06:05 -070076 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
77 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
Logan Chienf3511742017-10-31 18:04:35 +080078
79 return testCcWithConfig(t, bp, config)
80}
81
82func testCcNoVndk(t *testing.T, bp string) *android.TestContext {
Logan Chiend3c59a22018-03-29 14:08:15 +080083 t.Helper()
Logan Chienf3511742017-10-31 18:04:35 +080084 config := android.TestArchConfig(buildDir, nil)
Dan Willemsen674dc7f2018-03-12 18:06:05 -070085 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
Logan Chienf3511742017-10-31 18:04:35 +080086
87 return testCcWithConfig(t, bp, config)
88}
89
90func testCcError(t *testing.T, pattern string, bp string) {
Logan Chiend3c59a22018-03-29 14:08:15 +080091 t.Helper()
Logan Chienf3511742017-10-31 18:04:35 +080092 config := android.TestArchConfig(buildDir, nil)
Dan Willemsen674dc7f2018-03-12 18:06:05 -070093 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
94 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
Logan Chienf3511742017-10-31 18:04:35 +080095
Colin Cross9a942872019-05-14 15:44:26 -070096 ctx := CreateTestContext(bp, nil, android.Android)
Colin Cross33b2fb72019-05-14 14:07:01 -070097 ctx.Register()
Logan Chienf3511742017-10-31 18:04:35 +080098
99 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
100 if len(errs) > 0 {
Logan Chienee97c3e2018-03-12 16:34:26 +0800101 android.FailIfNoMatchingErrors(t, pattern, errs)
Logan Chienf3511742017-10-31 18:04:35 +0800102 return
103 }
104
105 _, errs = ctx.PrepareBuildActions(config)
106 if len(errs) > 0 {
Logan Chienee97c3e2018-03-12 16:34:26 +0800107 android.FailIfNoMatchingErrors(t, pattern, errs)
Logan Chienf3511742017-10-31 18:04:35 +0800108 return
109 }
110
111 t.Fatalf("missing expected error %q (0 errors are returned)", pattern)
112}
113
114const (
Jiyong Park5baac542018-08-28 09:55:37 +0900115 coreVariant = "android_arm64_armv8-a_core_shared"
Inseob Kim64c43952019-08-26 16:52:35 +0900116 vendorVariant = "android_arm64_armv8-a_vendor.VER_shared"
Jiyong Park5baac542018-08-28 09:55:37 +0900117 recoveryVariant = "android_arm64_armv8-a_recovery_shared"
Logan Chienf3511742017-10-31 18:04:35 +0800118)
119
Doug Hornc32c6b02019-01-17 14:44:05 -0800120func TestFuchsiaDeps(t *testing.T) {
121 t.Helper()
122
123 bp := `
124 cc_library {
125 name: "libTest",
126 srcs: ["foo.c"],
127 target: {
128 fuchsia: {
129 srcs: ["bar.c"],
130 },
131 },
132 }`
133
134 config := android.TestArchConfigFuchsia(buildDir, nil)
135 ctx := testCcWithConfigForOs(t, bp, config, android.Fuchsia)
136
137 rt := false
138 fb := false
139
140 ld := ctx.ModuleForTests("libTest", "fuchsia_arm64_shared").Rule("ld")
141 implicits := ld.Implicits
142 for _, lib := range implicits {
143 if strings.Contains(lib.Rel(), "libcompiler_rt") {
144 rt = true
145 }
146
147 if strings.Contains(lib.Rel(), "libbioniccompat") {
148 fb = true
149 }
150 }
151
152 if !rt || !fb {
153 t.Errorf("fuchsia libs must link libcompiler_rt and libbioniccompat")
154 }
155}
156
157func TestFuchsiaTargetDecl(t *testing.T) {
158 t.Helper()
159
160 bp := `
161 cc_library {
162 name: "libTest",
163 srcs: ["foo.c"],
164 target: {
165 fuchsia: {
166 srcs: ["bar.c"],
167 },
168 },
169 }`
170
171 config := android.TestArchConfigFuchsia(buildDir, nil)
172 ctx := testCcWithConfigForOs(t, bp, config, android.Fuchsia)
173 ld := ctx.ModuleForTests("libTest", "fuchsia_arm64_shared").Rule("ld")
174 var objs []string
175 for _, o := range ld.Inputs {
176 objs = append(objs, o.Base())
177 }
178 if len(objs) != 2 || objs[0] != "foo.o" || objs[1] != "bar.o" {
179 t.Errorf("inputs of libTest must be []string{\"foo.o\", \"bar.o\"}, but was %#v.", objs)
180 }
181}
182
Jiyong Park6a43f042017-10-12 23:05:00 +0900183func TestVendorSrc(t *testing.T) {
184 ctx := testCc(t, `
185 cc_library {
186 name: "libTest",
187 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -0700188 no_libcrt: true,
Logan Chienf3511742017-10-31 18:04:35 +0800189 nocrt: true,
190 system_shared_libs: [],
Jiyong Park6a43f042017-10-12 23:05:00 +0900191 vendor_available: true,
192 target: {
193 vendor: {
194 srcs: ["bar.c"],
195 },
196 },
197 }
Jiyong Park6a43f042017-10-12 23:05:00 +0900198 `)
199
Logan Chienf3511742017-10-31 18:04:35 +0800200 ld := ctx.ModuleForTests("libTest", vendorVariant).Rule("ld")
Jiyong Park6a43f042017-10-12 23:05:00 +0900201 var objs []string
202 for _, o := range ld.Inputs {
203 objs = append(objs, o.Base())
204 }
Colin Cross95d33fe2018-01-03 13:40:46 -0800205 if len(objs) != 2 || objs[0] != "foo.o" || objs[1] != "bar.o" {
Jiyong Park6a43f042017-10-12 23:05:00 +0900206 t.Errorf("inputs of libTest must be []string{\"foo.o\", \"bar.o\"}, but was %#v.", objs)
207 }
208}
209
Logan Chienf3511742017-10-31 18:04:35 +0800210func checkVndkModule(t *testing.T, ctx *android.TestContext, name, subDir string,
211 isVndkSp bool, extends string) {
212
Logan Chiend3c59a22018-03-29 14:08:15 +0800213 t.Helper()
214
Logan Chienf3511742017-10-31 18:04:35 +0800215 mod := ctx.ModuleForTests(name, vendorVariant).Module().(*Module)
Ivan Lozano52767be2019-10-18 14:49:46 -0700216 if !mod.HasVendorVariant() {
Colin Crossf46e37f2018-03-21 16:25:58 -0700217 t.Errorf("%q must have vendor variant", name)
Logan Chienf3511742017-10-31 18:04:35 +0800218 }
219
220 // Check library properties.
221 lib, ok := mod.compiler.(*libraryDecorator)
222 if !ok {
223 t.Errorf("%q must have libraryDecorator", name)
224 } else if lib.baseInstaller.subDir != subDir {
225 t.Errorf("%q must use %q as subdir but it is using %q", name, subDir,
226 lib.baseInstaller.subDir)
227 }
228
229 // Check VNDK properties.
230 if mod.vndkdep == nil {
231 t.Fatalf("%q must have `vndkdep`", name)
232 }
Ivan Lozano52767be2019-10-18 14:49:46 -0700233 if !mod.IsVndk() {
234 t.Errorf("%q IsVndk() must equal to true", name)
Logan Chienf3511742017-10-31 18:04:35 +0800235 }
236 if mod.isVndkSp() != isVndkSp {
237 t.Errorf("%q isVndkSp() must equal to %t", name, isVndkSp)
238 }
239
240 // Check VNDK extension properties.
241 isVndkExt := extends != ""
242 if mod.isVndkExt() != isVndkExt {
243 t.Errorf("%q isVndkExt() must equal to %t", name, isVndkExt)
244 }
245
246 if actualExtends := mod.getVndkExtendsModuleName(); actualExtends != extends {
247 t.Errorf("%q must extend from %q but get %q", name, extends, actualExtends)
248 }
249}
250
Inseob Kim1f086e22019-05-09 13:29:15 +0900251func checkVndkSnapshot(t *testing.T, ctx *android.TestContext, name, subDir, variant string) {
252 vndkSnapshot := ctx.SingletonForTests("vndk-snapshot")
253
254 snapshotPath := filepath.Join(subDir, name+".so")
255 mod := ctx.ModuleForTests(name, variant).Module().(*Module)
256 if !mod.outputFile.Valid() {
257 t.Errorf("%q must have output\n", name)
258 return
259 }
260
261 out := vndkSnapshot.Output(snapshotPath)
262 if out.Input != mod.outputFile.Path() {
263 t.Errorf("The input of VNDK snapshot must be %q, but %q", out.Input.String(), mod.outputFile.String())
264 }
265}
266
Jooyung Han097087b2019-10-22 19:32:18 +0900267func checkVndkOutput(t *testing.T, ctx *android.TestContext, output string, expected []string) {
268 t.Helper()
269 vndkSnapshot := ctx.SingletonForTests("vndk-snapshot")
270 actual := strings.FieldsFunc(strings.ReplaceAll(vndkSnapshot.Output(output).Args["content"], "\\n", "\n"), func(r rune) bool { return r == '\n' })
271 assertArrayString(t, actual, expected)
272}
273
Logan Chienf3511742017-10-31 18:04:35 +0800274func TestVndk(t *testing.T) {
Inseob Kim1f086e22019-05-09 13:29:15 +0900275 config := android.TestArchConfig(buildDir, nil)
276 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
277 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
278
279 ctx := testCcWithConfig(t, `
Logan Chienf3511742017-10-31 18:04:35 +0800280 cc_library {
281 name: "libvndk",
282 vendor_available: true,
283 vndk: {
284 enabled: true,
285 },
286 nocrt: true,
287 }
288
289 cc_library {
290 name: "libvndk_private",
291 vendor_available: false,
292 vndk: {
293 enabled: true,
294 },
295 nocrt: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900296 stem: "libvndk-private",
Logan Chienf3511742017-10-31 18:04:35 +0800297 }
298
299 cc_library {
300 name: "libvndk_sp",
301 vendor_available: true,
302 vndk: {
303 enabled: true,
304 support_system_process: true,
305 },
306 nocrt: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900307 suffix: "-x",
Logan Chienf3511742017-10-31 18:04:35 +0800308 }
309
310 cc_library {
311 name: "libvndk_sp_private",
312 vendor_available: false,
313 vndk: {
314 enabled: true,
315 support_system_process: true,
316 },
317 nocrt: true,
Jooyung Han0302a842019-10-30 18:43:49 +0900318 target: {
319 vendor: {
320 suffix: "-x",
321 },
322 },
Logan Chienf3511742017-10-31 18:04:35 +0800323 }
Inseob Kim1f086e22019-05-09 13:29:15 +0900324 `, config)
Logan Chienf3511742017-10-31 18:04:35 +0800325
326 checkVndkModule(t, ctx, "libvndk", "vndk-VER", false, "")
327 checkVndkModule(t, ctx, "libvndk_private", "vndk-VER", false, "")
328 checkVndkModule(t, ctx, "libvndk_sp", "vndk-sp-VER", true, "")
329 checkVndkModule(t, ctx, "libvndk_sp_private", "vndk-sp-VER", true, "")
Inseob Kim1f086e22019-05-09 13:29:15 +0900330
331 // Check VNDK snapshot output.
332
333 snapshotDir := "vndk-snapshot"
334 snapshotVariantPath := filepath.Join(buildDir, snapshotDir, "arm64")
335
336 vndkLibPath := filepath.Join(snapshotVariantPath, fmt.Sprintf("arch-%s-%s",
337 "arm64", "armv8-a"))
338 vndkLib2ndPath := filepath.Join(snapshotVariantPath, fmt.Sprintf("arch-%s-%s",
339 "arm", "armv7-a-neon"))
340
341 vndkCoreLibPath := filepath.Join(vndkLibPath, "shared", "vndk-core")
342 vndkSpLibPath := filepath.Join(vndkLibPath, "shared", "vndk-sp")
343 vndkCoreLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-core")
344 vndkSpLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-sp")
345
Inseob Kim64c43952019-08-26 16:52:35 +0900346 variant := "android_arm64_armv8-a_vendor.VER_shared"
347 variant2nd := "android_arm_armv7-a-neon_vendor.VER_shared"
Inseob Kim1f086e22019-05-09 13:29:15 +0900348
349 checkVndkSnapshot(t, ctx, "libvndk", vndkCoreLibPath, variant)
350 checkVndkSnapshot(t, ctx, "libvndk", vndkCoreLib2ndPath, variant2nd)
351 checkVndkSnapshot(t, ctx, "libvndk_sp", vndkSpLibPath, variant)
352 checkVndkSnapshot(t, ctx, "libvndk_sp", vndkSpLib2ndPath, variant2nd)
Jooyung Han097087b2019-10-22 19:32:18 +0900353
354 checkVndkOutput(t, ctx, "vndk/llndk.libraries.txt", []string{"libc.so", "libdl.so", "libft2.so", "libm.so"})
Jooyung Han0302a842019-10-30 18:43:49 +0900355 checkVndkOutput(t, ctx, "vndk/vndkcore.libraries.txt", []string{"libvndk-private.so", "libvndk.so"})
356 checkVndkOutput(t, ctx, "vndk/vndkprivate.libraries.txt", []string{"libft2.so", "libvndk-private.so", "libvndk_sp_private-x.so"})
357 checkVndkOutput(t, ctx, "vndk/vndksp.libraries.txt", []string{"libc++.so", "libvndk_sp-x.so", "libvndk_sp_private-x.so"})
Jooyung Han097087b2019-10-22 19:32:18 +0900358 checkVndkOutput(t, ctx, "vndk/vndkcorevariant.libraries.txt", nil)
359 // merged & tagged & filtered-out(libclang_rt)
360 checkVndkOutput(t, ctx, "vndk/vndk.libraries.txt", []string{
361 "LLNDK: libc.so",
362 "LLNDK: libdl.so",
363 "LLNDK: libft2.so",
364 "LLNDK: libm.so",
365 "VNDK-SP: libc++.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900366 "VNDK-SP: libvndk_sp-x.so",
367 "VNDK-SP: libvndk_sp_private-x.so",
368 "VNDK-core: libvndk-private.so",
Jooyung Han097087b2019-10-22 19:32:18 +0900369 "VNDK-core: libvndk.so",
Jooyung Han097087b2019-10-22 19:32:18 +0900370 "VNDK-private: libft2.so",
Jooyung Han0302a842019-10-30 18:43:49 +0900371 "VNDK-private: libvndk-private.so",
372 "VNDK-private: libvndk_sp_private-x.so",
Jooyung Han097087b2019-10-22 19:32:18 +0900373 })
Jooyung Han0302a842019-10-30 18:43:49 +0900374 checkVndkOutput(t, ctx, "vndk/llndk.libraries.txt", []string{
375 "libc.so", "libdl.so", "libft2.so", "libm.so",
376 })
377 checkVndkOutput(t, ctx, "vndk/vndkcore.libraries.txt", []string{
378 "libvndk-private.so", "libvndk.so",
379 })
380 checkVndkOutput(t, ctx, "vndk/vndksp.libraries.txt", []string{
381 "libc++.so", "libvndk_sp-x.so", "libvndk_sp_private-x.so",
382 })
383 checkVndkOutput(t, ctx, "vndk/vndkprivate.libraries.txt", []string{
384 "libft2.so", "libvndk-private.so", "libvndk_sp_private-x.so",
385 })
386 checkVndkOutput(t, ctx, "vndk/vndkcorevariant.libraries.txt", []string{})
Jooyung Han097087b2019-10-22 19:32:18 +0900387}
388
389func TestVndkUsingCoreVariant(t *testing.T) {
390 config := android.TestArchConfig(buildDir, nil)
391 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
392 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
393 config.TestProductVariables.VndkUseCoreVariant = BoolPtr(true)
394
395 setVndkMustUseVendorVariantListForTest(config, []string{"libvndk"})
396
397 ctx := testCcWithConfig(t, `
398 cc_library {
399 name: "libvndk",
400 vendor_available: true,
401 vndk: {
402 enabled: true,
403 },
404 nocrt: true,
405 }
406
407 cc_library {
408 name: "libvndk_sp",
409 vendor_available: true,
410 vndk: {
411 enabled: true,
412 support_system_process: true,
413 },
414 nocrt: true,
415 }
416
417 cc_library {
418 name: "libvndk2",
419 vendor_available: false,
420 vndk: {
421 enabled: true,
422 },
423 nocrt: true,
424 }
425 `, config)
426
427 checkVndkOutput(t, ctx, "vndk/vndkcore.libraries.txt", []string{"libvndk.so", "libvndk2.so"})
Jooyung Han0302a842019-10-30 18:43:49 +0900428 checkVndkOutput(t, ctx, "vndk/vndkcorevariant.libraries.txt", []string{
429 "libc++.so", "libvndk2.so", "libvndk_sp.so",
430 })
431}
432
433func TestVndkWhenVndkVersionIsNotSet(t *testing.T) {
434 config := android.TestArchConfig(buildDir, nil)
435 config.TestProductVariables.DeviceVndkVersion = nil
436 config.TestProductVariables.Platform_vndk_version = nil
437
438 ctx := testCcWithConfig(t, `
439 cc_library {
440 name: "libvndk",
441 vendor_available: true,
442 vndk: {
443 enabled: true,
444 },
445 nocrt: true,
446 }
447 `, config)
448
449 checkVndkOutput(t, ctx, "vndk/vndk.libraries.txt", []string{
450 "LLNDK: libc.so",
451 "LLNDK: libdl.so",
452 "LLNDK: libft2.so",
453 "LLNDK: libm.so",
454 "VNDK-SP: libc++.so",
455 "VNDK-core: libvndk.so",
456 "VNDK-private: libft2.so",
457 })
Logan Chienf3511742017-10-31 18:04:35 +0800458}
459
Logan Chiend3c59a22018-03-29 14:08:15 +0800460func TestVndkDepError(t *testing.T) {
461 // Check whether an error is emitted when a VNDK lib depends on a system lib.
462 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
463 cc_library {
464 name: "libvndk",
465 vendor_available: true,
466 vndk: {
467 enabled: true,
468 },
469 shared_libs: ["libfwk"], // Cause error
470 nocrt: true,
471 }
472
473 cc_library {
474 name: "libfwk",
475 nocrt: true,
476 }
477 `)
478
479 // Check whether an error is emitted when a VNDK lib depends on a vendor lib.
480 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
481 cc_library {
482 name: "libvndk",
483 vendor_available: true,
484 vndk: {
485 enabled: true,
486 },
487 shared_libs: ["libvendor"], // Cause error
488 nocrt: true,
489 }
490
491 cc_library {
492 name: "libvendor",
493 vendor: true,
494 nocrt: true,
495 }
496 `)
497
498 // Check whether an error is emitted when a VNDK-SP lib depends on a system lib.
499 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
500 cc_library {
501 name: "libvndk_sp",
502 vendor_available: true,
503 vndk: {
504 enabled: true,
505 support_system_process: true,
506 },
507 shared_libs: ["libfwk"], // Cause error
508 nocrt: true,
509 }
510
511 cc_library {
512 name: "libfwk",
513 nocrt: true,
514 }
515 `)
516
517 // Check whether an error is emitted when a VNDK-SP lib depends on a vendor lib.
518 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
519 cc_library {
520 name: "libvndk_sp",
521 vendor_available: true,
522 vndk: {
523 enabled: true,
524 support_system_process: true,
525 },
526 shared_libs: ["libvendor"], // Cause error
527 nocrt: true,
528 }
529
530 cc_library {
531 name: "libvendor",
532 vendor: true,
533 nocrt: true,
534 }
535 `)
536
537 // Check whether an error is emitted when a VNDK-SP lib depends on a VNDK lib.
538 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
539 cc_library {
540 name: "libvndk_sp",
541 vendor_available: true,
542 vndk: {
543 enabled: true,
544 support_system_process: true,
545 },
546 shared_libs: ["libvndk"], // Cause error
547 nocrt: true,
548 }
549
550 cc_library {
551 name: "libvndk",
552 vendor_available: true,
553 vndk: {
554 enabled: true,
555 },
556 nocrt: true,
557 }
558 `)
Jooyung Hana70f0672019-01-18 15:20:43 +0900559
560 // Check whether an error is emitted when a VNDK lib depends on a non-VNDK lib.
561 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
562 cc_library {
563 name: "libvndk",
564 vendor_available: true,
565 vndk: {
566 enabled: true,
567 },
568 shared_libs: ["libnonvndk"],
569 nocrt: true,
570 }
571
572 cc_library {
573 name: "libnonvndk",
574 vendor_available: true,
575 nocrt: true,
576 }
577 `)
578
579 // Check whether an error is emitted when a VNDK-private lib depends on a non-VNDK lib.
580 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
581 cc_library {
582 name: "libvndkprivate",
583 vendor_available: false,
584 vndk: {
585 enabled: true,
586 },
587 shared_libs: ["libnonvndk"],
588 nocrt: true,
589 }
590
591 cc_library {
592 name: "libnonvndk",
593 vendor_available: true,
594 nocrt: true,
595 }
596 `)
597
598 // Check whether an error is emitted when a VNDK-sp lib depends on a non-VNDK lib.
599 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
600 cc_library {
601 name: "libvndksp",
602 vendor_available: true,
603 vndk: {
604 enabled: true,
605 support_system_process: true,
606 },
607 shared_libs: ["libnonvndk"],
608 nocrt: true,
609 }
610
611 cc_library {
612 name: "libnonvndk",
613 vendor_available: true,
614 nocrt: true,
615 }
616 `)
617
618 // Check whether an error is emitted when a VNDK-sp-private lib depends on a non-VNDK lib.
619 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
620 cc_library {
621 name: "libvndkspprivate",
622 vendor_available: false,
623 vndk: {
624 enabled: true,
625 support_system_process: true,
626 },
627 shared_libs: ["libnonvndk"],
628 nocrt: true,
629 }
630
631 cc_library {
632 name: "libnonvndk",
633 vendor_available: true,
634 nocrt: true,
635 }
636 `)
637}
638
639func TestDoubleLoadbleDep(t *testing.T) {
640 // okay to link : LLNDK -> double_loadable VNDK
641 testCc(t, `
642 cc_library {
643 name: "libllndk",
644 shared_libs: ["libdoubleloadable"],
645 }
646
647 llndk_library {
648 name: "libllndk",
649 symbol_file: "",
650 }
651
652 cc_library {
653 name: "libdoubleloadable",
654 vendor_available: true,
655 vndk: {
656 enabled: true,
657 },
658 double_loadable: true,
659 }
660 `)
661 // okay to link : LLNDK -> VNDK-SP
662 testCc(t, `
663 cc_library {
664 name: "libllndk",
665 shared_libs: ["libvndksp"],
666 }
667
668 llndk_library {
669 name: "libllndk",
670 symbol_file: "",
671 }
672
673 cc_library {
674 name: "libvndksp",
675 vendor_available: true,
676 vndk: {
677 enabled: true,
678 support_system_process: true,
679 },
680 }
681 `)
682 // okay to link : double_loadable -> double_loadable
683 testCc(t, `
684 cc_library {
685 name: "libdoubleloadable1",
686 shared_libs: ["libdoubleloadable2"],
687 vendor_available: true,
688 double_loadable: true,
689 }
690
691 cc_library {
692 name: "libdoubleloadable2",
693 vendor_available: true,
694 double_loadable: true,
695 }
696 `)
697 // okay to link : double_loadable VNDK -> double_loadable VNDK private
698 testCc(t, `
699 cc_library {
700 name: "libdoubleloadable",
701 vendor_available: true,
702 vndk: {
703 enabled: true,
704 },
705 double_loadable: true,
706 shared_libs: ["libnondoubleloadable"],
707 }
708
709 cc_library {
710 name: "libnondoubleloadable",
711 vendor_available: false,
712 vndk: {
713 enabled: true,
714 },
715 double_loadable: true,
716 }
717 `)
718 // okay to link : LLNDK -> core-only -> vendor_available & double_loadable
719 testCc(t, `
720 cc_library {
721 name: "libllndk",
722 shared_libs: ["libcoreonly"],
723 }
724
725 llndk_library {
726 name: "libllndk",
727 symbol_file: "",
728 }
729
730 cc_library {
731 name: "libcoreonly",
732 shared_libs: ["libvendoravailable"],
733 }
734
735 // indirect dependency of LLNDK
736 cc_library {
737 name: "libvendoravailable",
738 vendor_available: true,
739 double_loadable: true,
740 }
741 `)
742}
743
744func TestDoubleLoadableDepError(t *testing.T) {
745 // Check whether an error is emitted when a LLNDK depends on a non-double_loadable VNDK lib.
746 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
747 cc_library {
748 name: "libllndk",
749 shared_libs: ["libnondoubleloadable"],
750 }
751
752 llndk_library {
753 name: "libllndk",
754 symbol_file: "",
755 }
756
757 cc_library {
758 name: "libnondoubleloadable",
759 vendor_available: true,
760 vndk: {
761 enabled: true,
762 },
763 }
764 `)
765
766 // Check whether an error is emitted when a LLNDK depends on a non-double_loadable vendor_available lib.
767 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
768 cc_library {
769 name: "libllndk",
Yi Konge7fe9912019-06-02 00:53:50 -0700770 no_libcrt: true,
Jooyung Hana70f0672019-01-18 15:20:43 +0900771 shared_libs: ["libnondoubleloadable"],
772 }
773
774 llndk_library {
775 name: "libllndk",
776 symbol_file: "",
777 }
778
779 cc_library {
780 name: "libnondoubleloadable",
781 vendor_available: true,
782 }
783 `)
784
785 // Check whether an error is emitted when a double_loadable lib depends on a non-double_loadable vendor_available lib.
786 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
787 cc_library {
788 name: "libdoubleloadable",
789 vendor_available: true,
790 double_loadable: true,
791 shared_libs: ["libnondoubleloadable"],
792 }
793
794 cc_library {
795 name: "libnondoubleloadable",
796 vendor_available: true,
797 }
798 `)
799
800 // Check whether an error is emitted when a double_loadable lib depends on a non-double_loadable VNDK lib.
801 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
802 cc_library {
803 name: "libdoubleloadable",
804 vendor_available: true,
805 double_loadable: true,
806 shared_libs: ["libnondoubleloadable"],
807 }
808
809 cc_library {
810 name: "libnondoubleloadable",
811 vendor_available: true,
812 vndk: {
813 enabled: true,
814 },
815 }
816 `)
817
818 // Check whether an error is emitted when a double_loadable VNDK depends on a non-double_loadable VNDK private lib.
819 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
820 cc_library {
821 name: "libdoubleloadable",
822 vendor_available: true,
823 vndk: {
824 enabled: true,
825 },
826 double_loadable: true,
827 shared_libs: ["libnondoubleloadable"],
828 }
829
830 cc_library {
831 name: "libnondoubleloadable",
832 vendor_available: false,
833 vndk: {
834 enabled: true,
835 },
836 }
837 `)
838
839 // Check whether an error is emitted when a LLNDK depends on a non-double_loadable indirectly.
840 testCcError(t, "module \".*\" variant \".*\": link.* \".*\" which is not LL-NDK, VNDK-SP, .*double_loadable", `
841 cc_library {
842 name: "libllndk",
843 shared_libs: ["libcoreonly"],
844 }
845
846 llndk_library {
847 name: "libllndk",
848 symbol_file: "",
849 }
850
851 cc_library {
852 name: "libcoreonly",
853 shared_libs: ["libvendoravailable"],
854 }
855
856 // indirect dependency of LLNDK
857 cc_library {
858 name: "libvendoravailable",
859 vendor_available: true,
860 }
861 `)
Logan Chiend3c59a22018-03-29 14:08:15 +0800862}
863
Justin Yun9357f4a2018-11-28 15:14:47 +0900864func TestVndkMustNotBeProductSpecific(t *testing.T) {
865 // Check whether an error is emitted when a vndk lib has 'product_specific: true'.
866 testCcError(t, "product_specific must not be true when `vndk: {enabled: true}`", `
867 cc_library {
868 name: "libvndk",
869 product_specific: true, // Cause error
870 vendor_available: true,
871 vndk: {
872 enabled: true,
873 },
874 nocrt: true,
875 }
876 `)
877}
878
Logan Chienf3511742017-10-31 18:04:35 +0800879func TestVndkExt(t *testing.T) {
880 // This test checks the VNDK-Ext properties.
881 ctx := testCc(t, `
882 cc_library {
883 name: "libvndk",
884 vendor_available: true,
885 vndk: {
886 enabled: true,
887 },
888 nocrt: true,
889 }
Jooyung Han4c2b9422019-10-22 19:53:47 +0900890 cc_library {
891 name: "libvndk2",
892 vendor_available: true,
893 vndk: {
894 enabled: true,
895 },
896 target: {
897 vendor: {
898 suffix: "-suffix",
899 },
900 },
901 nocrt: true,
902 }
Logan Chienf3511742017-10-31 18:04:35 +0800903
904 cc_library {
905 name: "libvndk_ext",
906 vendor: true,
907 vndk: {
908 enabled: true,
909 extends: "libvndk",
910 },
911 nocrt: true,
912 }
Jooyung Han4c2b9422019-10-22 19:53:47 +0900913
914 cc_library {
915 name: "libvndk2_ext",
916 vendor: true,
917 vndk: {
918 enabled: true,
919 extends: "libvndk2",
920 },
921 nocrt: true,
922 }
Logan Chienf3511742017-10-31 18:04:35 +0800923 `)
924
925 checkVndkModule(t, ctx, "libvndk_ext", "vndk", false, "libvndk")
Jooyung Han4c2b9422019-10-22 19:53:47 +0900926
927 mod := ctx.ModuleForTests("libvndk2_ext", vendorVariant).Module().(*Module)
928 assertString(t, mod.outputFile.Path().Base(), "libvndk2-suffix.so")
Logan Chienf3511742017-10-31 18:04:35 +0800929}
930
Logan Chiend3c59a22018-03-29 14:08:15 +0800931func TestVndkExtWithoutBoardVndkVersion(t *testing.T) {
Logan Chienf3511742017-10-31 18:04:35 +0800932 // This test checks the VNDK-Ext properties when BOARD_VNDK_VERSION is not set.
933 ctx := testCcNoVndk(t, `
934 cc_library {
935 name: "libvndk",
936 vendor_available: true,
937 vndk: {
938 enabled: true,
939 },
940 nocrt: true,
941 }
942
943 cc_library {
944 name: "libvndk_ext",
945 vendor: true,
946 vndk: {
947 enabled: true,
948 extends: "libvndk",
949 },
950 nocrt: true,
951 }
952 `)
953
954 // Ensures that the core variant of "libvndk_ext" can be found.
955 mod := ctx.ModuleForTests("libvndk_ext", coreVariant).Module().(*Module)
956 if extends := mod.getVndkExtendsModuleName(); extends != "libvndk" {
957 t.Errorf("\"libvndk_ext\" must extend from \"libvndk\" but get %q", extends)
958 }
959}
960
961func TestVndkExtError(t *testing.T) {
962 // This test ensures an error is emitted in ill-formed vndk-ext definition.
963 testCcError(t, "must set `vendor: true` to set `extends: \".*\"`", `
964 cc_library {
965 name: "libvndk",
966 vendor_available: true,
967 vndk: {
968 enabled: true,
969 },
970 nocrt: true,
971 }
972
973 cc_library {
974 name: "libvndk_ext",
975 vndk: {
976 enabled: true,
977 extends: "libvndk",
978 },
979 nocrt: true,
980 }
981 `)
982
983 testCcError(t, "must set `extends: \"\\.\\.\\.\"` to vndk extension", `
984 cc_library {
985 name: "libvndk",
986 vendor_available: true,
987 vndk: {
988 enabled: true,
989 },
990 nocrt: true,
991 }
992
993 cc_library {
994 name: "libvndk_ext",
995 vendor: true,
996 vndk: {
997 enabled: true,
998 },
999 nocrt: true,
1000 }
1001 `)
1002}
1003
1004func TestVndkExtInconsistentSupportSystemProcessError(t *testing.T) {
1005 // This test ensures an error is emitted for inconsistent support_system_process.
1006 testCcError(t, "module \".*\" with mismatched support_system_process", `
1007 cc_library {
1008 name: "libvndk",
1009 vendor_available: true,
1010 vndk: {
1011 enabled: true,
1012 },
1013 nocrt: true,
1014 }
1015
1016 cc_library {
1017 name: "libvndk_sp_ext",
1018 vendor: true,
1019 vndk: {
1020 enabled: true,
1021 extends: "libvndk",
1022 support_system_process: true,
1023 },
1024 nocrt: true,
1025 }
1026 `)
1027
1028 testCcError(t, "module \".*\" with mismatched support_system_process", `
1029 cc_library {
1030 name: "libvndk_sp",
1031 vendor_available: true,
1032 vndk: {
1033 enabled: true,
1034 support_system_process: true,
1035 },
1036 nocrt: true,
1037 }
1038
1039 cc_library {
1040 name: "libvndk_ext",
1041 vendor: true,
1042 vndk: {
1043 enabled: true,
1044 extends: "libvndk_sp",
1045 },
1046 nocrt: true,
1047 }
1048 `)
1049}
1050
1051func TestVndkExtVendorAvailableFalseError(t *testing.T) {
Logan Chiend3c59a22018-03-29 14:08:15 +08001052 // This test ensures an error is emitted when a VNDK-Ext library extends a VNDK library
Logan Chienf3511742017-10-31 18:04:35 +08001053 // with `vendor_available: false`.
1054 testCcError(t, "`extends` refers module \".*\" which does not have `vendor_available: true`", `
1055 cc_library {
1056 name: "libvndk",
1057 vendor_available: false,
1058 vndk: {
1059 enabled: true,
1060 },
1061 nocrt: true,
1062 }
1063
1064 cc_library {
1065 name: "libvndk_ext",
1066 vendor: true,
1067 vndk: {
1068 enabled: true,
1069 extends: "libvndk",
1070 },
1071 nocrt: true,
1072 }
1073 `)
1074}
1075
Logan Chiend3c59a22018-03-29 14:08:15 +08001076func TestVendorModuleUseVndkExt(t *testing.T) {
1077 // This test ensures a vendor module can depend on a VNDK-Ext library.
Logan Chienf3511742017-10-31 18:04:35 +08001078 testCc(t, `
1079 cc_library {
1080 name: "libvndk",
1081 vendor_available: true,
1082 vndk: {
1083 enabled: true,
1084 },
1085 nocrt: true,
1086 }
1087
1088 cc_library {
1089 name: "libvndk_ext",
1090 vendor: true,
1091 vndk: {
1092 enabled: true,
1093 extends: "libvndk",
1094 },
1095 nocrt: true,
1096 }
1097
1098 cc_library {
1099
1100 name: "libvndk_sp",
1101 vendor_available: true,
1102 vndk: {
1103 enabled: true,
1104 support_system_process: true,
1105 },
1106 nocrt: true,
1107 }
1108
1109 cc_library {
1110 name: "libvndk_sp_ext",
1111 vendor: true,
1112 vndk: {
1113 enabled: true,
1114 extends: "libvndk_sp",
1115 support_system_process: true,
1116 },
1117 nocrt: true,
1118 }
1119
1120 cc_library {
1121 name: "libvendor",
1122 vendor: true,
1123 shared_libs: ["libvndk_ext", "libvndk_sp_ext"],
1124 nocrt: true,
1125 }
1126 `)
1127}
1128
Logan Chiend3c59a22018-03-29 14:08:15 +08001129func TestVndkExtUseVendorLib(t *testing.T) {
1130 // This test ensures a VNDK-Ext library can depend on a vendor library.
Logan Chienf3511742017-10-31 18:04:35 +08001131 testCc(t, `
1132 cc_library {
1133 name: "libvndk",
1134 vendor_available: true,
1135 vndk: {
1136 enabled: true,
1137 },
1138 nocrt: true,
1139 }
1140
1141 cc_library {
1142 name: "libvndk_ext",
1143 vendor: true,
1144 vndk: {
1145 enabled: true,
1146 extends: "libvndk",
1147 },
1148 shared_libs: ["libvendor"],
1149 nocrt: true,
1150 }
1151
1152 cc_library {
1153 name: "libvendor",
1154 vendor: true,
1155 nocrt: true,
1156 }
1157 `)
Logan Chienf3511742017-10-31 18:04:35 +08001158
Logan Chiend3c59a22018-03-29 14:08:15 +08001159 // This test ensures a VNDK-SP-Ext library can depend on a vendor library.
1160 testCc(t, `
Logan Chienf3511742017-10-31 18:04:35 +08001161 cc_library {
1162 name: "libvndk_sp",
1163 vendor_available: true,
1164 vndk: {
1165 enabled: true,
1166 support_system_process: true,
1167 },
1168 nocrt: true,
1169 }
1170
1171 cc_library {
1172 name: "libvndk_sp_ext",
1173 vendor: true,
1174 vndk: {
1175 enabled: true,
1176 extends: "libvndk_sp",
1177 support_system_process: true,
1178 },
1179 shared_libs: ["libvendor"], // Cause an error
1180 nocrt: true,
1181 }
1182
1183 cc_library {
1184 name: "libvendor",
1185 vendor: true,
1186 nocrt: true,
1187 }
1188 `)
1189}
1190
Logan Chiend3c59a22018-03-29 14:08:15 +08001191func TestVndkSpExtUseVndkError(t *testing.T) {
1192 // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK
1193 // library.
1194 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
1195 cc_library {
1196 name: "libvndk",
1197 vendor_available: true,
1198 vndk: {
1199 enabled: true,
1200 },
1201 nocrt: true,
1202 }
1203
1204 cc_library {
1205 name: "libvndk_sp",
1206 vendor_available: true,
1207 vndk: {
1208 enabled: true,
1209 support_system_process: true,
1210 },
1211 nocrt: true,
1212 }
1213
1214 cc_library {
1215 name: "libvndk_sp_ext",
1216 vendor: true,
1217 vndk: {
1218 enabled: true,
1219 extends: "libvndk_sp",
1220 support_system_process: true,
1221 },
1222 shared_libs: ["libvndk"], // Cause an error
1223 nocrt: true,
1224 }
1225 `)
1226
1227 // This test ensures an error is emitted if a VNDK-SP-Ext library depends on a VNDK-Ext
1228 // library.
1229 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
1230 cc_library {
1231 name: "libvndk",
1232 vendor_available: true,
1233 vndk: {
1234 enabled: true,
1235 },
1236 nocrt: true,
1237 }
1238
1239 cc_library {
1240 name: "libvndk_ext",
1241 vendor: true,
1242 vndk: {
1243 enabled: true,
1244 extends: "libvndk",
1245 },
1246 nocrt: true,
1247 }
1248
1249 cc_library {
1250 name: "libvndk_sp",
1251 vendor_available: true,
1252 vndk: {
1253 enabled: true,
1254 support_system_process: true,
1255 },
1256 nocrt: true,
1257 }
1258
1259 cc_library {
1260 name: "libvndk_sp_ext",
1261 vendor: true,
1262 vndk: {
1263 enabled: true,
1264 extends: "libvndk_sp",
1265 support_system_process: true,
1266 },
1267 shared_libs: ["libvndk_ext"], // Cause an error
1268 nocrt: true,
1269 }
1270 `)
1271}
1272
1273func TestVndkUseVndkExtError(t *testing.T) {
1274 // This test ensures an error is emitted if a VNDK/VNDK-SP library depends on a
1275 // VNDK-Ext/VNDK-SP-Ext library.
Logan Chienf3511742017-10-31 18:04:35 +08001276 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
1277 cc_library {
1278 name: "libvndk",
1279 vendor_available: true,
1280 vndk: {
1281 enabled: true,
1282 },
1283 nocrt: true,
1284 }
1285
1286 cc_library {
1287 name: "libvndk_ext",
1288 vendor: true,
1289 vndk: {
1290 enabled: true,
1291 extends: "libvndk",
1292 },
1293 nocrt: true,
1294 }
1295
1296 cc_library {
1297 name: "libvndk2",
1298 vendor_available: true,
1299 vndk: {
1300 enabled: true,
1301 },
1302 shared_libs: ["libvndk_ext"],
1303 nocrt: true,
1304 }
1305 `)
1306
Martin Stjernholmef449fe2018-11-06 16:12:13 +00001307 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
Logan Chienf3511742017-10-31 18:04:35 +08001308 cc_library {
1309 name: "libvndk",
1310 vendor_available: true,
1311 vndk: {
1312 enabled: true,
1313 },
1314 nocrt: true,
1315 }
1316
1317 cc_library {
1318 name: "libvndk_ext",
1319 vendor: true,
1320 vndk: {
1321 enabled: true,
1322 extends: "libvndk",
1323 },
1324 nocrt: true,
1325 }
1326
1327 cc_library {
1328 name: "libvndk2",
1329 vendor_available: true,
1330 vndk: {
1331 enabled: true,
1332 },
1333 target: {
1334 vendor: {
1335 shared_libs: ["libvndk_ext"],
1336 },
1337 },
1338 nocrt: true,
1339 }
1340 `)
1341
1342 testCcError(t, "dependency \".*\" of \".*\" missing variant", `
1343 cc_library {
1344 name: "libvndk_sp",
1345 vendor_available: true,
1346 vndk: {
1347 enabled: true,
1348 support_system_process: true,
1349 },
1350 nocrt: true,
1351 }
1352
1353 cc_library {
1354 name: "libvndk_sp_ext",
1355 vendor: true,
1356 vndk: {
1357 enabled: true,
1358 extends: "libvndk_sp",
1359 support_system_process: true,
1360 },
1361 nocrt: true,
1362 }
1363
1364 cc_library {
1365 name: "libvndk_sp_2",
1366 vendor_available: true,
1367 vndk: {
1368 enabled: true,
1369 support_system_process: true,
1370 },
1371 shared_libs: ["libvndk_sp_ext"],
1372 nocrt: true,
1373 }
1374 `)
1375
Martin Stjernholmef449fe2018-11-06 16:12:13 +00001376 testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
Logan Chienf3511742017-10-31 18:04:35 +08001377 cc_library {
1378 name: "libvndk_sp",
1379 vendor_available: true,
1380 vndk: {
1381 enabled: true,
1382 },
1383 nocrt: true,
1384 }
1385
1386 cc_library {
1387 name: "libvndk_sp_ext",
1388 vendor: true,
1389 vndk: {
1390 enabled: true,
1391 extends: "libvndk_sp",
1392 },
1393 nocrt: true,
1394 }
1395
1396 cc_library {
1397 name: "libvndk_sp2",
1398 vendor_available: true,
1399 vndk: {
1400 enabled: true,
1401 },
1402 target: {
1403 vendor: {
1404 shared_libs: ["libvndk_sp_ext"],
1405 },
1406 },
1407 nocrt: true,
1408 }
1409 `)
1410}
1411
Jooyung Han38002912019-05-16 04:01:54 +09001412func TestMakeLinkType(t *testing.T) {
1413 config := android.TestArchConfig(buildDir, nil)
1414 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
1415 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
1416 // native:vndk
1417 ctx := testCcWithConfig(t, `
1418 cc_library {
1419 name: "libvndk",
1420 vendor_available: true,
1421 vndk: {
1422 enabled: true,
1423 },
1424 }
1425 cc_library {
1426 name: "libvndksp",
1427 vendor_available: true,
1428 vndk: {
1429 enabled: true,
1430 support_system_process: true,
1431 },
1432 }
1433 cc_library {
1434 name: "libvndkprivate",
1435 vendor_available: false,
1436 vndk: {
1437 enabled: true,
1438 },
1439 }
1440 cc_library {
1441 name: "libvendor",
1442 vendor: true,
1443 }
1444 cc_library {
1445 name: "libvndkext",
1446 vendor: true,
1447 vndk: {
1448 enabled: true,
1449 extends: "libvndk",
1450 },
1451 }
1452 vndk_prebuilt_shared {
1453 name: "prevndk",
1454 version: "27",
1455 target_arch: "arm",
1456 binder32bit: true,
1457 vendor_available: true,
1458 vndk: {
1459 enabled: true,
1460 },
1461 arch: {
1462 arm: {
1463 srcs: ["liba.so"],
1464 },
1465 },
1466 }
1467 cc_library {
1468 name: "libllndk",
1469 }
1470 llndk_library {
1471 name: "libllndk",
1472 symbol_file: "",
1473 }
1474 cc_library {
1475 name: "libllndkprivate",
1476 }
1477 llndk_library {
1478 name: "libllndkprivate",
1479 vendor_available: false,
1480 symbol_file: "",
1481 }`, config)
1482
Jooyung Han0302a842019-10-30 18:43:49 +09001483 assertMapKeys(t, vndkCoreLibraries(config),
Jooyung Han38002912019-05-16 04:01:54 +09001484 []string{"libvndk", "libvndkprivate"})
Jooyung Han0302a842019-10-30 18:43:49 +09001485 assertMapKeys(t, vndkSpLibraries(config),
Jooyung Han38002912019-05-16 04:01:54 +09001486 []string{"libc++", "libvndksp"})
Jooyung Han0302a842019-10-30 18:43:49 +09001487 assertMapKeys(t, llndkLibraries(config),
Jooyung Han097087b2019-10-22 19:32:18 +09001488 []string{"libc", "libdl", "libft2", "libllndk", "libllndkprivate", "libm"})
Jooyung Han0302a842019-10-30 18:43:49 +09001489 assertMapKeys(t, vndkPrivateLibraries(config),
Jooyung Han097087b2019-10-22 19:32:18 +09001490 []string{"libft2", "libllndkprivate", "libvndkprivate"})
Jooyung Han38002912019-05-16 04:01:54 +09001491
Inseob Kim64c43952019-08-26 16:52:35 +09001492 vendorVariant27 := "android_arm64_armv8-a_vendor.27_shared"
1493
Jooyung Han38002912019-05-16 04:01:54 +09001494 tests := []struct {
1495 variant string
1496 name string
1497 expected string
1498 }{
1499 {vendorVariant, "libvndk", "native:vndk"},
1500 {vendorVariant, "libvndksp", "native:vndk"},
1501 {vendorVariant, "libvndkprivate", "native:vndk_private"},
1502 {vendorVariant, "libvendor", "native:vendor"},
1503 {vendorVariant, "libvndkext", "native:vendor"},
Jooyung Han38002912019-05-16 04:01:54 +09001504 {vendorVariant, "libllndk.llndk", "native:vndk"},
Inseob Kim64c43952019-08-26 16:52:35 +09001505 {vendorVariant27, "prevndk.vndk.27.arm.binder32", "native:vndk"},
Jooyung Han38002912019-05-16 04:01:54 +09001506 {coreVariant, "libvndk", "native:platform"},
1507 {coreVariant, "libvndkprivate", "native:platform"},
1508 {coreVariant, "libllndk", "native:platform"},
1509 }
1510 for _, test := range tests {
1511 t.Run(test.name, func(t *testing.T) {
1512 module := ctx.ModuleForTests(test.name, test.variant).Module().(*Module)
1513 assertString(t, module.makeLinkType, test.expected)
1514 })
1515 }
1516}
1517
Colin Cross0af4b842015-04-30 16:36:18 -07001518var (
1519 str11 = "01234567891"
1520 str10 = str11[:10]
1521 str9 = str11[:9]
1522 str5 = str11[:5]
1523 str4 = str11[:4]
1524)
1525
1526var splitListForSizeTestCases = []struct {
1527 in []string
1528 out [][]string
1529 size int
1530}{
1531 {
1532 in: []string{str10},
1533 out: [][]string{{str10}},
1534 size: 10,
1535 },
1536 {
1537 in: []string{str9},
1538 out: [][]string{{str9}},
1539 size: 10,
1540 },
1541 {
1542 in: []string{str5},
1543 out: [][]string{{str5}},
1544 size: 10,
1545 },
1546 {
1547 in: []string{str11},
1548 out: nil,
1549 size: 10,
1550 },
1551 {
1552 in: []string{str10, str10},
1553 out: [][]string{{str10}, {str10}},
1554 size: 10,
1555 },
1556 {
1557 in: []string{str9, str10},
1558 out: [][]string{{str9}, {str10}},
1559 size: 10,
1560 },
1561 {
1562 in: []string{str10, str9},
1563 out: [][]string{{str10}, {str9}},
1564 size: 10,
1565 },
1566 {
1567 in: []string{str5, str4},
1568 out: [][]string{{str5, str4}},
1569 size: 10,
1570 },
1571 {
1572 in: []string{str5, str4, str5},
1573 out: [][]string{{str5, str4}, {str5}},
1574 size: 10,
1575 },
1576 {
1577 in: []string{str5, str4, str5, str4},
1578 out: [][]string{{str5, str4}, {str5, str4}},
1579 size: 10,
1580 },
1581 {
1582 in: []string{str5, str4, str5, str5},
1583 out: [][]string{{str5, str4}, {str5}, {str5}},
1584 size: 10,
1585 },
1586 {
1587 in: []string{str5, str5, str5, str4},
1588 out: [][]string{{str5}, {str5}, {str5, str4}},
1589 size: 10,
1590 },
1591 {
1592 in: []string{str9, str11},
1593 out: nil,
1594 size: 10,
1595 },
1596 {
1597 in: []string{str11, str9},
1598 out: nil,
1599 size: 10,
1600 },
1601}
1602
1603func TestSplitListForSize(t *testing.T) {
1604 for _, testCase := range splitListForSizeTestCases {
Colin Cross40e33732019-02-15 11:08:35 -08001605 out, _ := splitListForSize(android.PathsForTesting(testCase.in...), testCase.size)
Colin Cross5b529592017-05-09 13:34:34 -07001606
1607 var outStrings [][]string
1608
1609 if len(out) > 0 {
1610 outStrings = make([][]string, len(out))
1611 for i, o := range out {
1612 outStrings[i] = o.Strings()
1613 }
1614 }
1615
1616 if !reflect.DeepEqual(outStrings, testCase.out) {
Colin Cross0af4b842015-04-30 16:36:18 -07001617 t.Errorf("incorrect output:")
1618 t.Errorf(" input: %#v", testCase.in)
1619 t.Errorf(" size: %d", testCase.size)
1620 t.Errorf(" expected: %#v", testCase.out)
Colin Cross5b529592017-05-09 13:34:34 -07001621 t.Errorf(" got: %#v", outStrings)
Colin Cross0af4b842015-04-30 16:36:18 -07001622 }
1623 }
1624}
Jeff Gaston294356f2017-09-27 17:05:30 -07001625
1626var staticLinkDepOrderTestCases = []struct {
1627 // This is a string representation of a map[moduleName][]moduleDependency .
1628 // It models the dependencies declared in an Android.bp file.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001629 inStatic string
1630
1631 // This is a string representation of a map[moduleName][]moduleDependency .
1632 // It models the dependencies declared in an Android.bp file.
1633 inShared string
Jeff Gaston294356f2017-09-27 17:05:30 -07001634
1635 // allOrdered is a string representation of a map[moduleName][]moduleDependency .
1636 // The keys of allOrdered specify which modules we would like to check.
1637 // The values of allOrdered specify the expected result (of the transitive closure of all
1638 // dependencies) for each module to test
1639 allOrdered string
1640
1641 // outOrdered is a string representation of a map[moduleName][]moduleDependency .
1642 // The keys of outOrdered specify which modules we would like to check.
1643 // The values of outOrdered specify the expected result (of the ordered linker command line)
1644 // for each module to test.
1645 outOrdered string
1646}{
1647 // Simple tests
1648 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001649 inStatic: "",
Jeff Gaston294356f2017-09-27 17:05:30 -07001650 outOrdered: "",
1651 },
1652 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001653 inStatic: "a:",
Jeff Gaston294356f2017-09-27 17:05:30 -07001654 outOrdered: "a:",
1655 },
1656 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001657 inStatic: "a:b; b:",
Jeff Gaston294356f2017-09-27 17:05:30 -07001658 outOrdered: "a:b; b:",
1659 },
1660 // Tests of reordering
1661 {
1662 // diamond example
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001663 inStatic: "a:d,b,c; b:d; c:d; d:",
Jeff Gaston294356f2017-09-27 17:05:30 -07001664 outOrdered: "a:b,c,d; b:d; c:d; d:",
1665 },
1666 {
1667 // somewhat real example
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001668 inStatic: "bsdiff_unittest:b,c,d,e,f,g,h,i; e:b",
Jeff Gaston294356f2017-09-27 17:05:30 -07001669 outOrdered: "bsdiff_unittest:c,d,e,b,f,g,h,i; e:b",
1670 },
1671 {
1672 // multiple reorderings
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001673 inStatic: "a:b,c,d,e; d:b; e:c",
Jeff Gaston294356f2017-09-27 17:05:30 -07001674 outOrdered: "a:d,b,e,c; d:b; e:c",
1675 },
1676 {
1677 // should reorder without adding new transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001678 inStatic: "bin:lib2,lib1; lib1:lib2,liboptional",
Jeff Gaston294356f2017-09-27 17:05:30 -07001679 allOrdered: "bin:lib1,lib2,liboptional; lib1:lib2,liboptional",
1680 outOrdered: "bin:lib1,lib2; lib1:lib2,liboptional",
1681 },
1682 {
1683 // multiple levels of dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001684 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 -07001685 allOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d",
1686 outOrdered: "a:e,f,b,c,d,g,h; f:b,c,d; b:c,d; c:d",
1687 },
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001688 // shared dependencies
1689 {
1690 // Note that this test doesn't recurse, to minimize the amount of logic it tests.
1691 // So, we don't actually have to check that a shared dependency of c will change the order
1692 // of a library that depends statically on b and on c. We only need to check that if c has
1693 // a shared dependency on b, that that shows up in allOrdered.
1694 inShared: "c:b",
1695 allOrdered: "c:b",
1696 outOrdered: "c:",
1697 },
1698 {
1699 // This test doesn't actually include any shared dependencies but it's a reminder of what
1700 // the second phase of the above test would look like
1701 inStatic: "a:b,c; c:b",
1702 allOrdered: "a:c,b; c:b",
1703 outOrdered: "a:c,b; c:b",
1704 },
Jeff Gaston294356f2017-09-27 17:05:30 -07001705 // tiebreakers for when two modules specifying different orderings and there is no dependency
1706 // to dictate an order
1707 {
1708 // 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 -08001709 inStatic: "a1:b,c,d,e; a2:b,c,e,d; b:d,e; c:e,d",
Jeff Gaston294356f2017-09-27 17:05:30 -07001710 outOrdered: "a1:b,c,d,e; a2:b,c,e,d; b:d,e; c:e,d",
1711 },
1712 {
1713 // 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 -08001714 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 -07001715 outOrdered: "a1:b1,c1,e,d; b1:d,e; c1:e,d; a2:b2,c2,d,e; b2:d,e; c2:d,e",
1716 },
1717 // Tests involving duplicate dependencies
1718 {
1719 // simple duplicate
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001720 inStatic: "a:b,c,c,b",
Jeff Gaston294356f2017-09-27 17:05:30 -07001721 outOrdered: "a:c,b",
1722 },
1723 {
1724 // duplicates with reordering
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001725 inStatic: "a:b,c,d,c; c:b",
Jeff Gaston294356f2017-09-27 17:05:30 -07001726 outOrdered: "a:d,c,b",
1727 },
1728 // Tests to confirm the nonexistence of infinite loops.
1729 // These cases should never happen, so as long as the test terminates and the
1730 // result is deterministic then that should be fine.
1731 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001732 inStatic: "a:a",
Jeff Gaston294356f2017-09-27 17:05:30 -07001733 outOrdered: "a:a",
1734 },
1735 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001736 inStatic: "a:b; b:c; c:a",
Jeff Gaston294356f2017-09-27 17:05:30 -07001737 allOrdered: "a:b,c; b:c,a; c:a,b",
1738 outOrdered: "a:b; b:c; c:a",
1739 },
1740 {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001741 inStatic: "a:b,c; b:c,a; c:a,b",
Jeff Gaston294356f2017-09-27 17:05:30 -07001742 allOrdered: "a:c,a,b; b:a,b,c; c:b,c,a",
1743 outOrdered: "a:c,b; b:a,c; c:b,a",
1744 },
1745}
1746
1747// converts from a string like "a:b,c; d:e" to (["a","b"], {"a":["b","c"], "d":["e"]}, [{"a", "a.o"}, {"b", "b.o"}])
1748func parseModuleDeps(text string) (modulesInOrder []android.Path, allDeps map[android.Path][]android.Path) {
1749 // convert from "a:b,c; d:e" to "a:b,c;d:e"
1750 strippedText := strings.Replace(text, " ", "", -1)
1751 if len(strippedText) < 1 {
1752 return []android.Path{}, make(map[android.Path][]android.Path, 0)
1753 }
1754 allDeps = make(map[android.Path][]android.Path, 0)
1755
1756 // convert from "a:b,c;d:e" to ["a:b,c", "d:e"]
1757 moduleTexts := strings.Split(strippedText, ";")
1758
1759 outputForModuleName := func(moduleName string) android.Path {
1760 return android.PathForTesting(moduleName)
1761 }
1762
1763 for _, moduleText := range moduleTexts {
1764 // convert from "a:b,c" to ["a", "b,c"]
1765 components := strings.Split(moduleText, ":")
1766 if len(components) != 2 {
1767 panic(fmt.Sprintf("illegal module dep string %q from larger string %q; must contain one ':', not %v", moduleText, text, len(components)-1))
1768 }
1769 moduleName := components[0]
1770 moduleOutput := outputForModuleName(moduleName)
1771 modulesInOrder = append(modulesInOrder, moduleOutput)
1772
1773 depString := components[1]
1774 // convert from "b,c" to ["b", "c"]
1775 depNames := strings.Split(depString, ",")
1776 if len(depString) < 1 {
1777 depNames = []string{}
1778 }
1779 var deps []android.Path
1780 for _, depName := range depNames {
1781 deps = append(deps, outputForModuleName(depName))
1782 }
1783 allDeps[moduleOutput] = deps
1784 }
1785 return modulesInOrder, allDeps
1786}
1787
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001788func TestLinkReordering(t *testing.T) {
Jeff Gaston294356f2017-09-27 17:05:30 -07001789 for _, testCase := range staticLinkDepOrderTestCases {
1790 errs := []string{}
1791
1792 // parse testcase
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001793 _, givenTransitiveDeps := parseModuleDeps(testCase.inStatic)
Jeff Gaston294356f2017-09-27 17:05:30 -07001794 expectedModuleNames, expectedTransitiveDeps := parseModuleDeps(testCase.outOrdered)
1795 if testCase.allOrdered == "" {
1796 // allow the test case to skip specifying allOrdered
1797 testCase.allOrdered = testCase.outOrdered
1798 }
1799 _, expectedAllDeps := parseModuleDeps(testCase.allOrdered)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001800 _, givenAllSharedDeps := parseModuleDeps(testCase.inShared)
Jeff Gaston294356f2017-09-27 17:05:30 -07001801
1802 // For each module whose post-reordered dependencies were specified, validate that
1803 // reordering the inputs produces the expected outputs.
1804 for _, moduleName := range expectedModuleNames {
1805 moduleDeps := givenTransitiveDeps[moduleName]
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001806 givenSharedDeps := givenAllSharedDeps[moduleName]
1807 orderedAllDeps, orderedDeclaredDeps := orderDeps(moduleDeps, givenSharedDeps, givenTransitiveDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001808
1809 correctAllOrdered := expectedAllDeps[moduleName]
1810 if !reflect.DeepEqual(orderedAllDeps, correctAllOrdered) {
1811 errs = append(errs, fmt.Sprintf("orderDeps returned incorrect orderedAllDeps."+
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001812 "\nin static:%q"+
1813 "\nin shared:%q"+
Jeff Gaston294356f2017-09-27 17:05:30 -07001814 "\nmodule: %v"+
1815 "\nexpected: %s"+
1816 "\nactual: %s",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001817 testCase.inStatic, testCase.inShared, moduleName, correctAllOrdered, orderedAllDeps))
Jeff Gaston294356f2017-09-27 17:05:30 -07001818 }
1819
1820 correctOutputDeps := expectedTransitiveDeps[moduleName]
1821 if !reflect.DeepEqual(correctOutputDeps, orderedDeclaredDeps) {
1822 errs = append(errs, fmt.Sprintf("orderDeps returned incorrect orderedDeclaredDeps."+
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001823 "\nin static:%q"+
1824 "\nin shared:%q"+
Jeff Gaston294356f2017-09-27 17:05:30 -07001825 "\nmodule: %v"+
1826 "\nexpected: %s"+
1827 "\nactual: %s",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001828 testCase.inStatic, testCase.inShared, moduleName, correctOutputDeps, orderedDeclaredDeps))
Jeff Gaston294356f2017-09-27 17:05:30 -07001829 }
1830 }
1831
1832 if len(errs) > 0 {
1833 sort.Strings(errs)
1834 for _, err := range errs {
1835 t.Error(err)
1836 }
1837 }
1838 }
1839}
Logan Chienf3511742017-10-31 18:04:35 +08001840
Jeff Gaston294356f2017-09-27 17:05:30 -07001841func getOutputPaths(ctx *android.TestContext, variant string, moduleNames []string) (paths android.Paths) {
1842 for _, moduleName := range moduleNames {
1843 module := ctx.ModuleForTests(moduleName, variant).Module().(*Module)
1844 output := module.outputFile.Path()
1845 paths = append(paths, output)
1846 }
1847 return paths
1848}
1849
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001850func TestStaticLibDepReordering(t *testing.T) {
Jeff Gaston294356f2017-09-27 17:05:30 -07001851 ctx := testCc(t, `
1852 cc_library {
1853 name: "a",
1854 static_libs: ["b", "c", "d"],
Jiyong Park374510b2018-03-19 18:23:01 +09001855 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07001856 }
1857 cc_library {
1858 name: "b",
Jiyong Park374510b2018-03-19 18:23:01 +09001859 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07001860 }
1861 cc_library {
1862 name: "c",
1863 static_libs: ["b"],
Jiyong Park374510b2018-03-19 18:23:01 +09001864 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07001865 }
1866 cc_library {
1867 name: "d",
Jiyong Park374510b2018-03-19 18:23:01 +09001868 stl: "none",
Jeff Gaston294356f2017-09-27 17:05:30 -07001869 }
1870
1871 `)
1872
1873 variant := "android_arm64_armv8-a_core_static"
1874 moduleA := ctx.ModuleForTests("a", variant).Module().(*Module)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001875 actual := moduleA.depsInLinkOrder
Jeff Gaston294356f2017-09-27 17:05:30 -07001876 expected := getOutputPaths(ctx, variant, []string{"c", "b", "d"})
1877
1878 if !reflect.DeepEqual(actual, expected) {
1879 t.Errorf("staticDeps orderings were not propagated correctly"+
1880 "\nactual: %v"+
1881 "\nexpected: %v",
1882 actual,
1883 expected,
1884 )
1885 }
Jiyong Parkd08b6972017-09-26 10:50:54 +09001886}
Jeff Gaston294356f2017-09-27 17:05:30 -07001887
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001888func TestStaticLibDepReorderingWithShared(t *testing.T) {
1889 ctx := testCc(t, `
1890 cc_library {
1891 name: "a",
1892 static_libs: ["b", "c"],
Jiyong Park374510b2018-03-19 18:23:01 +09001893 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001894 }
1895 cc_library {
1896 name: "b",
Jiyong Park374510b2018-03-19 18:23:01 +09001897 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001898 }
1899 cc_library {
1900 name: "c",
1901 shared_libs: ["b"],
Jiyong Park374510b2018-03-19 18:23:01 +09001902 stl: "none",
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001903 }
1904
1905 `)
1906
1907 variant := "android_arm64_armv8-a_core_static"
1908 moduleA := ctx.ModuleForTests("a", variant).Module().(*Module)
1909 actual := moduleA.depsInLinkOrder
1910 expected := getOutputPaths(ctx, variant, []string{"c", "b"})
1911
1912 if !reflect.DeepEqual(actual, expected) {
1913 t.Errorf("staticDeps orderings did not account for shared libs"+
1914 "\nactual: %v"+
1915 "\nexpected: %v",
1916 actual,
1917 expected,
1918 )
1919 }
1920}
1921
Jiyong Parka46a4d52017-12-14 19:54:34 +09001922func TestLlndkHeaders(t *testing.T) {
1923 ctx := testCc(t, `
1924 llndk_headers {
1925 name: "libllndk_headers",
1926 export_include_dirs: ["my_include"],
1927 }
1928 llndk_library {
1929 name: "libllndk",
1930 export_llndk_headers: ["libllndk_headers"],
1931 }
1932 cc_library {
1933 name: "libvendor",
1934 shared_libs: ["libllndk"],
1935 vendor: true,
1936 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -07001937 no_libcrt: true,
Logan Chienf3511742017-10-31 18:04:35 +08001938 nocrt: true,
Jiyong Parka46a4d52017-12-14 19:54:34 +09001939 }
1940 `)
1941
1942 // _static variant is used since _shared reuses *.o from the static variant
Inseob Kim64c43952019-08-26 16:52:35 +09001943 cc := ctx.ModuleForTests("libvendor", "android_arm_armv7-a-neon_vendor.VER_static").Rule("cc")
Jiyong Parka46a4d52017-12-14 19:54:34 +09001944 cflags := cc.Args["cFlags"]
1945 if !strings.Contains(cflags, "-Imy_include") {
1946 t.Errorf("cflags for libvendor must contain -Imy_include, but was %#v.", cflags)
1947 }
1948}
1949
Logan Chien43d34c32017-12-20 01:17:32 +08001950func checkRuntimeLibs(t *testing.T, expected []string, module *Module) {
1951 actual := module.Properties.AndroidMkRuntimeLibs
1952 if !reflect.DeepEqual(actual, expected) {
1953 t.Errorf("incorrect runtime_libs for shared libs"+
1954 "\nactual: %v"+
1955 "\nexpected: %v",
1956 actual,
1957 expected,
1958 )
1959 }
1960}
1961
1962const runtimeLibAndroidBp = `
1963 cc_library {
1964 name: "libvendor_available1",
1965 vendor_available: true,
Yi Konge7fe9912019-06-02 00:53:50 -07001966 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08001967 nocrt : true,
1968 system_shared_libs : [],
1969 }
1970 cc_library {
1971 name: "libvendor_available2",
1972 vendor_available: true,
1973 runtime_libs: ["libvendor_available1"],
Yi Konge7fe9912019-06-02 00:53:50 -07001974 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08001975 nocrt : true,
1976 system_shared_libs : [],
1977 }
1978 cc_library {
1979 name: "libvendor_available3",
1980 vendor_available: true,
1981 runtime_libs: ["libvendor_available1"],
1982 target: {
1983 vendor: {
1984 exclude_runtime_libs: ["libvendor_available1"],
1985 }
1986 },
Yi Konge7fe9912019-06-02 00:53:50 -07001987 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08001988 nocrt : true,
1989 system_shared_libs : [],
1990 }
1991 cc_library {
1992 name: "libcore",
1993 runtime_libs: ["libvendor_available1"],
Yi Konge7fe9912019-06-02 00:53:50 -07001994 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08001995 nocrt : true,
1996 system_shared_libs : [],
1997 }
1998 cc_library {
1999 name: "libvendor1",
2000 vendor: true,
Yi Konge7fe9912019-06-02 00:53:50 -07002001 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002002 nocrt : true,
2003 system_shared_libs : [],
2004 }
2005 cc_library {
2006 name: "libvendor2",
2007 vendor: true,
2008 runtime_libs: ["libvendor_available1", "libvendor1"],
Yi Konge7fe9912019-06-02 00:53:50 -07002009 no_libcrt : true,
Logan Chien43d34c32017-12-20 01:17:32 +08002010 nocrt : true,
2011 system_shared_libs : [],
2012 }
2013`
2014
2015func TestRuntimeLibs(t *testing.T) {
2016 ctx := testCc(t, runtimeLibAndroidBp)
2017
2018 // runtime_libs for core variants use the module names without suffixes.
2019 variant := "android_arm64_armv8-a_core_shared"
2020
2021 module := ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module)
2022 checkRuntimeLibs(t, []string{"libvendor_available1"}, module)
2023
2024 module = ctx.ModuleForTests("libcore", variant).Module().(*Module)
2025 checkRuntimeLibs(t, []string{"libvendor_available1"}, module)
2026
2027 // runtime_libs for vendor variants have '.vendor' suffixes if the modules have both core
2028 // and vendor variants.
Inseob Kim64c43952019-08-26 16:52:35 +09002029 variant = "android_arm64_armv8-a_vendor.VER_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08002030
2031 module = ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module)
2032 checkRuntimeLibs(t, []string{"libvendor_available1.vendor"}, module)
2033
2034 module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module)
2035 checkRuntimeLibs(t, []string{"libvendor_available1.vendor", "libvendor1"}, module)
2036}
2037
2038func TestExcludeRuntimeLibs(t *testing.T) {
2039 ctx := testCc(t, runtimeLibAndroidBp)
2040
2041 variant := "android_arm64_armv8-a_core_shared"
2042 module := ctx.ModuleForTests("libvendor_available3", variant).Module().(*Module)
2043 checkRuntimeLibs(t, []string{"libvendor_available1"}, module)
2044
Inseob Kim64c43952019-08-26 16:52:35 +09002045 variant = "android_arm64_armv8-a_vendor.VER_shared"
Logan Chien43d34c32017-12-20 01:17:32 +08002046 module = ctx.ModuleForTests("libvendor_available3", variant).Module().(*Module)
2047 checkRuntimeLibs(t, nil, module)
2048}
2049
2050func TestRuntimeLibsNoVndk(t *testing.T) {
2051 ctx := testCcNoVndk(t, runtimeLibAndroidBp)
2052
2053 // If DeviceVndkVersion is not defined, then runtime_libs are copied as-is.
2054
2055 variant := "android_arm64_armv8-a_core_shared"
2056
2057 module := ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module)
2058 checkRuntimeLibs(t, []string{"libvendor_available1"}, module)
2059
2060 module = ctx.ModuleForTests("libvendor2", variant).Module().(*Module)
2061 checkRuntimeLibs(t, []string{"libvendor_available1", "libvendor1"}, module)
2062}
2063
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002064func checkStaticLibs(t *testing.T, expected []string, module *Module) {
2065 actual := module.Properties.AndroidMkStaticLibs
2066 if !reflect.DeepEqual(actual, expected) {
2067 t.Errorf("incorrect static_libs"+
2068 "\nactual: %v"+
2069 "\nexpected: %v",
2070 actual,
2071 expected,
2072 )
2073 }
2074}
2075
2076const staticLibAndroidBp = `
2077 cc_library {
2078 name: "lib1",
2079 }
2080 cc_library {
2081 name: "lib2",
2082 static_libs: ["lib1"],
2083 }
2084`
2085
2086func TestStaticLibDepExport(t *testing.T) {
2087 ctx := testCc(t, staticLibAndroidBp)
2088
2089 // Check the shared version of lib2.
2090 variant := "android_arm64_armv8-a_core_shared"
2091 module := ctx.ModuleForTests("lib2", variant).Module().(*Module)
Dan Albert2da19cb2019-07-24 12:17:40 -07002092 checkStaticLibs(t, []string{"lib1", "libc++demangle", "libclang_rt.builtins-aarch64-android", "libatomic", "libgcc_stripped"}, module)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002093
2094 // Check the static version of lib2.
2095 variant = "android_arm64_armv8-a_core_static"
2096 module = ctx.ModuleForTests("lib2", variant).Module().(*Module)
2097 // libc++_static is linked additionally.
Dan Albert2da19cb2019-07-24 12:17:40 -07002098 checkStaticLibs(t, []string{"lib1", "libc++_static", "libc++demangle", "libclang_rt.builtins-aarch64-android", "libatomic", "libgcc_stripped"}, module)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002099}
2100
Jiyong Parkd08b6972017-09-26 10:50:54 +09002101var compilerFlagsTestCases = []struct {
2102 in string
2103 out bool
2104}{
2105 {
2106 in: "a",
2107 out: false,
2108 },
2109 {
2110 in: "-a",
2111 out: true,
2112 },
2113 {
2114 in: "-Ipath/to/something",
2115 out: false,
2116 },
2117 {
2118 in: "-isystempath/to/something",
2119 out: false,
2120 },
2121 {
2122 in: "--coverage",
2123 out: false,
2124 },
2125 {
2126 in: "-include a/b",
2127 out: true,
2128 },
2129 {
2130 in: "-include a/b c/d",
2131 out: false,
2132 },
2133 {
2134 in: "-DMACRO",
2135 out: true,
2136 },
2137 {
2138 in: "-DMAC RO",
2139 out: false,
2140 },
2141 {
2142 in: "-a -b",
2143 out: false,
2144 },
2145 {
2146 in: "-DMACRO=definition",
2147 out: true,
2148 },
2149 {
2150 in: "-DMACRO=defi nition",
2151 out: true, // TODO(jiyong): this should be false
2152 },
2153 {
2154 in: "-DMACRO(x)=x + 1",
2155 out: true,
2156 },
2157 {
2158 in: "-DMACRO=\"defi nition\"",
2159 out: true,
2160 },
2161}
2162
2163type mockContext struct {
2164 BaseModuleContext
2165 result bool
2166}
2167
2168func (ctx *mockContext) PropertyErrorf(property, format string, args ...interface{}) {
2169 // CheckBadCompilerFlags calls this function when the flag should be rejected
2170 ctx.result = false
2171}
2172
2173func TestCompilerFlags(t *testing.T) {
2174 for _, testCase := range compilerFlagsTestCases {
2175 ctx := &mockContext{result: true}
2176 CheckBadCompilerFlags(ctx, "", []string{testCase.in})
2177 if ctx.result != testCase.out {
2178 t.Errorf("incorrect output:")
2179 t.Errorf(" input: %#v", testCase.in)
2180 t.Errorf(" expected: %#v", testCase.out)
2181 t.Errorf(" got: %#v", ctx.result)
2182 }
2183 }
Jeff Gaston294356f2017-09-27 17:05:30 -07002184}
Jiyong Park374510b2018-03-19 18:23:01 +09002185
2186func TestVendorPublicLibraries(t *testing.T) {
2187 ctx := testCc(t, `
2188 cc_library_headers {
2189 name: "libvendorpublic_headers",
2190 export_include_dirs: ["my_include"],
2191 }
2192 vendor_public_library {
2193 name: "libvendorpublic",
2194 symbol_file: "",
2195 export_public_headers: ["libvendorpublic_headers"],
2196 }
2197 cc_library {
2198 name: "libvendorpublic",
2199 srcs: ["foo.c"],
2200 vendor: true,
Yi Konge7fe9912019-06-02 00:53:50 -07002201 no_libcrt: true,
Jiyong Park374510b2018-03-19 18:23:01 +09002202 nocrt: true,
2203 }
2204
2205 cc_library {
2206 name: "libsystem",
2207 shared_libs: ["libvendorpublic"],
2208 vendor: false,
2209 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -07002210 no_libcrt: true,
Jiyong Park374510b2018-03-19 18:23:01 +09002211 nocrt: true,
2212 }
2213 cc_library {
2214 name: "libvendor",
2215 shared_libs: ["libvendorpublic"],
2216 vendor: true,
2217 srcs: ["foo.c"],
Yi Konge7fe9912019-06-02 00:53:50 -07002218 no_libcrt: true,
Jiyong Park374510b2018-03-19 18:23:01 +09002219 nocrt: true,
2220 }
2221 `)
2222
2223 variant := "android_arm64_armv8-a_core_shared"
2224
2225 // test if header search paths are correctly added
2226 // _static variant is used since _shared reuses *.o from the static variant
2227 cc := ctx.ModuleForTests("libsystem", strings.Replace(variant, "_shared", "_static", 1)).Rule("cc")
2228 cflags := cc.Args["cFlags"]
2229 if !strings.Contains(cflags, "-Imy_include") {
2230 t.Errorf("cflags for libsystem must contain -Imy_include, but was %#v.", cflags)
2231 }
2232
2233 // test if libsystem is linked to the stub
2234 ld := ctx.ModuleForTests("libsystem", variant).Rule("ld")
2235 libflags := ld.Args["libFlags"]
2236 stubPaths := getOutputPaths(ctx, variant, []string{"libvendorpublic" + vendorPublicLibrarySuffix})
2237 if !strings.Contains(libflags, stubPaths[0].String()) {
2238 t.Errorf("libflags for libsystem must contain %#v, but was %#v", stubPaths[0], libflags)
2239 }
2240
2241 // test if libvendor is linked to the real shared lib
Inseob Kim64c43952019-08-26 16:52:35 +09002242 ld = ctx.ModuleForTests("libvendor", strings.Replace(variant, "_core", "_vendor.VER", 1)).Rule("ld")
Jiyong Park374510b2018-03-19 18:23:01 +09002243 libflags = ld.Args["libFlags"]
Inseob Kim64c43952019-08-26 16:52:35 +09002244 stubPaths = getOutputPaths(ctx, strings.Replace(variant, "_core", "_vendor.VER", 1), []string{"libvendorpublic"})
Jiyong Park374510b2018-03-19 18:23:01 +09002245 if !strings.Contains(libflags, stubPaths[0].String()) {
2246 t.Errorf("libflags for libvendor must contain %#v, but was %#v", stubPaths[0], libflags)
2247 }
2248
2249}
Jiyong Park37b25202018-07-11 10:49:27 +09002250
2251func TestRecovery(t *testing.T) {
2252 ctx := testCc(t, `
2253 cc_library_shared {
2254 name: "librecovery",
2255 recovery: true,
2256 }
2257 cc_library_shared {
2258 name: "librecovery32",
2259 recovery: true,
2260 compile_multilib:"32",
2261 }
Jiyong Park5baac542018-08-28 09:55:37 +09002262 cc_library_shared {
2263 name: "libHalInRecovery",
2264 recovery_available: true,
2265 vendor: true,
2266 }
Jiyong Park37b25202018-07-11 10:49:27 +09002267 `)
2268
2269 variants := ctx.ModuleVariantsForTests("librecovery")
2270 const arm64 = "android_arm64_armv8-a_recovery_shared"
2271 if len(variants) != 1 || !android.InList(arm64, variants) {
2272 t.Errorf("variants of librecovery must be \"%s\" only, but was %#v", arm64, variants)
2273 }
2274
2275 variants = ctx.ModuleVariantsForTests("librecovery32")
2276 if android.InList(arm64, variants) {
2277 t.Errorf("multilib was set to 32 for librecovery32, but its variants has %s.", arm64)
2278 }
Jiyong Park5baac542018-08-28 09:55:37 +09002279
2280 recoveryModule := ctx.ModuleForTests("libHalInRecovery", recoveryVariant).Module().(*Module)
2281 if !recoveryModule.Platform() {
2282 t.Errorf("recovery variant of libHalInRecovery must not specific to device, soc, or product")
2283 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09002284}
Jiyong Park5baac542018-08-28 09:55:37 +09002285
Jiyong Park7ed9de32018-10-15 22:25:07 +09002286func TestVersionedStubs(t *testing.T) {
2287 ctx := testCc(t, `
2288 cc_library_shared {
2289 name: "libFoo",
Jiyong Parkda732bd2018-11-02 18:23:15 +09002290 srcs: ["foo.c"],
Jiyong Park7ed9de32018-10-15 22:25:07 +09002291 stubs: {
2292 symbol_file: "foo.map.txt",
2293 versions: ["1", "2", "3"],
2294 },
2295 }
Jiyong Parkda732bd2018-11-02 18:23:15 +09002296
Jiyong Park7ed9de32018-10-15 22:25:07 +09002297 cc_library_shared {
2298 name: "libBar",
Jiyong Parkda732bd2018-11-02 18:23:15 +09002299 srcs: ["bar.c"],
Jiyong Park7ed9de32018-10-15 22:25:07 +09002300 shared_libs: ["libFoo#1"],
2301 }`)
2302
2303 variants := ctx.ModuleVariantsForTests("libFoo")
2304 expectedVariants := []string{
2305 "android_arm64_armv8-a_core_shared",
2306 "android_arm64_armv8-a_core_shared_1",
2307 "android_arm64_armv8-a_core_shared_2",
2308 "android_arm64_armv8-a_core_shared_3",
2309 "android_arm_armv7-a-neon_core_shared",
2310 "android_arm_armv7-a-neon_core_shared_1",
2311 "android_arm_armv7-a-neon_core_shared_2",
2312 "android_arm_armv7-a-neon_core_shared_3",
2313 }
2314 variantsMismatch := false
2315 if len(variants) != len(expectedVariants) {
2316 variantsMismatch = true
2317 } else {
2318 for _, v := range expectedVariants {
2319 if !inList(v, variants) {
2320 variantsMismatch = false
2321 }
2322 }
2323 }
2324 if variantsMismatch {
2325 t.Errorf("variants of libFoo expected:\n")
2326 for _, v := range expectedVariants {
2327 t.Errorf("%q\n", v)
2328 }
2329 t.Errorf(", but got:\n")
2330 for _, v := range variants {
2331 t.Errorf("%q\n", v)
2332 }
2333 }
2334
2335 libBarLinkRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_core_shared").Rule("ld")
2336 libFlags := libBarLinkRule.Args["libFlags"]
2337 libFoo1StubPath := "libFoo/android_arm64_armv8-a_core_shared_1/libFoo.so"
2338 if !strings.Contains(libFlags, libFoo1StubPath) {
2339 t.Errorf("%q is not found in %q", libFoo1StubPath, libFlags)
2340 }
Jiyong Parkda732bd2018-11-02 18:23:15 +09002341
2342 libBarCompileRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_core_shared").Rule("cc")
2343 cFlags := libBarCompileRule.Args["cFlags"]
2344 libFoo1VersioningMacro := "-D__LIBFOO_API__=1"
2345 if !strings.Contains(cFlags, libFoo1VersioningMacro) {
2346 t.Errorf("%q is not found in %q", libFoo1VersioningMacro, cFlags)
2347 }
Jiyong Park37b25202018-07-11 10:49:27 +09002348}
Jaewoong Jung232c07c2018-12-18 11:08:25 -08002349
2350func TestStaticExecutable(t *testing.T) {
2351 ctx := testCc(t, `
2352 cc_binary {
2353 name: "static_test",
Pete Bentleyfcf55bf2019-08-16 20:14:32 +01002354 srcs: ["foo.c", "baz.o"],
Jaewoong Jung232c07c2018-12-18 11:08:25 -08002355 static_executable: true,
2356 }`)
2357
2358 variant := "android_arm64_armv8-a_core"
2359 binModuleRule := ctx.ModuleForTests("static_test", variant).Rule("ld")
2360 libFlags := binModuleRule.Args["libFlags"]
Ryan Prichardb49fe1b2019-10-11 15:03:34 -07002361 systemStaticLibs := []string{"libc.a", "libm.a"}
Jaewoong Jung232c07c2018-12-18 11:08:25 -08002362 for _, lib := range systemStaticLibs {
2363 if !strings.Contains(libFlags, lib) {
2364 t.Errorf("Static lib %q was not found in %q", lib, libFlags)
2365 }
2366 }
2367 systemSharedLibs := []string{"libc.so", "libm.so", "libdl.so"}
2368 for _, lib := range systemSharedLibs {
2369 if strings.Contains(libFlags, lib) {
2370 t.Errorf("Shared lib %q was found in %q", lib, libFlags)
2371 }
2372 }
2373}
Jiyong Parke4bb9862019-02-01 00:31:10 +09002374
2375func TestStaticDepsOrderWithStubs(t *testing.T) {
2376 ctx := testCc(t, `
2377 cc_binary {
2378 name: "mybin",
2379 srcs: ["foo.c"],
2380 static_libs: ["libB"],
2381 static_executable: true,
2382 stl: "none",
2383 }
2384
2385 cc_library {
2386 name: "libB",
2387 srcs: ["foo.c"],
2388 shared_libs: ["libC"],
2389 stl: "none",
2390 }
2391
2392 cc_library {
2393 name: "libC",
2394 srcs: ["foo.c"],
2395 stl: "none",
2396 stubs: {
2397 versions: ["1"],
2398 },
2399 }`)
2400
2401 mybin := ctx.ModuleForTests("mybin", "android_arm64_armv8-a_core").Module().(*Module)
2402 actual := mybin.depsInLinkOrder
2403 expected := getOutputPaths(ctx, "android_arm64_armv8-a_core_static", []string{"libB", "libC"})
2404
2405 if !reflect.DeepEqual(actual, expected) {
2406 t.Errorf("staticDeps orderings were not propagated correctly"+
2407 "\nactual: %v"+
2408 "\nexpected: %v",
2409 actual,
2410 expected,
2411 )
2412 }
2413}
Jooyung Han38002912019-05-16 04:01:54 +09002414
Jooyung Hand48f3c32019-08-23 11:18:57 +09002415func TestErrorsIfAModuleDependsOnDisabled(t *testing.T) {
2416 testCcError(t, `module "libA" .* depends on disabled module "libB"`, `
2417 cc_library {
2418 name: "libA",
2419 srcs: ["foo.c"],
2420 shared_libs: ["libB"],
2421 stl: "none",
2422 }
2423
2424 cc_library {
2425 name: "libB",
2426 srcs: ["foo.c"],
2427 enabled: false,
2428 stl: "none",
2429 }
2430 `)
2431}
2432
Mitch Phillipsda9a4632019-07-15 09:34:09 -07002433// Simple smoke test for the cc_fuzz target that ensures the rule compiles
2434// correctly.
2435func TestFuzzTarget(t *testing.T) {
2436 ctx := testCc(t, `
2437 cc_fuzz {
2438 name: "fuzz_smoke_test",
2439 srcs: ["foo.c"],
2440 }`)
2441
2442 variant := "android_arm64_armv8-a_core"
2443 ctx.ModuleForTests("fuzz_smoke_test", variant).Rule("cc")
2444}
2445
Jiyong Park29074592019-07-07 16:27:47 +09002446func TestAidl(t *testing.T) {
2447}
2448
Jooyung Han38002912019-05-16 04:01:54 +09002449func assertString(t *testing.T, got, expected string) {
2450 t.Helper()
2451 if got != expected {
2452 t.Errorf("expected %q got %q", expected, got)
2453 }
2454}
2455
2456func assertArrayString(t *testing.T, got, expected []string) {
2457 t.Helper()
2458 if len(got) != len(expected) {
2459 t.Errorf("expected %d (%q) got (%d) %q", len(expected), expected, len(got), got)
2460 return
2461 }
2462 for i := range got {
2463 if got[i] != expected[i] {
2464 t.Errorf("expected %d-th %q (%q) got %q (%q)",
2465 i, expected[i], expected, got[i], got)
2466 return
2467 }
2468 }
2469}
Colin Crosse1bb5d02019-09-24 14:55:04 -07002470
Jooyung Han0302a842019-10-30 18:43:49 +09002471func assertMapKeys(t *testing.T, m map[string]string, expected []string) {
2472 t.Helper()
2473 assertArrayString(t, android.SortedStringKeys(m), expected)
2474}
2475
Colin Crosse1bb5d02019-09-24 14:55:04 -07002476func TestDefaults(t *testing.T) {
2477 ctx := testCc(t, `
2478 cc_defaults {
2479 name: "defaults",
2480 srcs: ["foo.c"],
2481 static: {
2482 srcs: ["bar.c"],
2483 },
2484 shared: {
2485 srcs: ["baz.c"],
2486 },
2487 }
2488
2489 cc_library_static {
2490 name: "libstatic",
2491 defaults: ["defaults"],
2492 }
2493
2494 cc_library_shared {
2495 name: "libshared",
2496 defaults: ["defaults"],
2497 }
2498
2499 cc_library {
2500 name: "libboth",
2501 defaults: ["defaults"],
2502 }
2503
2504 cc_binary {
2505 name: "binary",
2506 defaults: ["defaults"],
2507 }`)
2508
2509 pathsToBase := func(paths android.Paths) []string {
2510 var ret []string
2511 for _, p := range paths {
2512 ret = append(ret, p.Base())
2513 }
2514 return ret
2515 }
2516
2517 shared := ctx.ModuleForTests("libshared", "android_arm64_armv8-a_core_shared").Rule("ld")
2518 if g, w := pathsToBase(shared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) {
2519 t.Errorf("libshared ld rule wanted %q, got %q", w, g)
2520 }
2521 bothShared := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_core_shared").Rule("ld")
2522 if g, w := pathsToBase(bothShared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) {
2523 t.Errorf("libboth ld rule wanted %q, got %q", w, g)
2524 }
2525 binary := ctx.ModuleForTests("binary", "android_arm64_armv8-a_core").Rule("ld")
2526 if g, w := pathsToBase(binary.Inputs), []string{"foo.o"}; !reflect.DeepEqual(w, g) {
2527 t.Errorf("binary ld rule wanted %q, got %q", w, g)
2528 }
2529
2530 static := ctx.ModuleForTests("libstatic", "android_arm64_armv8-a_core_static").Rule("ar")
2531 if g, w := pathsToBase(static.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) {
2532 t.Errorf("libstatic ar rule wanted %q, got %q", w, g)
2533 }
2534 bothStatic := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_core_static").Rule("ar")
2535 if g, w := pathsToBase(bothStatic.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) {
2536 t.Errorf("libboth ar rule wanted %q, got %q", w, g)
2537 }
2538}